c# - WebClient set headers -


how can set header in webclient class? tried:

client.headers["content-type"] = "image/jpeg"; 

that throws webexception

my code:

webclient client = new webclient(); client.headers.set("content-type", "image/png"); client.headers.set("content-length", length); client.headers.add("slug", name); namevaluecollection nvc = new namevaluecollection(); nvc.add("file", filecontents);  byte[] data = client.uploadvalues(url, nvc); string res = encoding.ascii.getstring(data); response.write(res); 

if header exists:

client.headers.set("content-type", "image/jpeg"); 

if new header:

client.headers.add("content-type", "image/jpeg"); 

also, there chance getting error because trying set headers late. post exception can let know.

update

looks there weird restrictions on "content-type" header webclient class. in using client.download methods (downloaddata, downloadfile, etc...)

see if using "uploadfile" method on webclient works rather doing manually. returns respose body byte[].

if continue have issues webclient, try justing using plain old httprequest/httpwebrequest.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -