WebClient set headers

后端 未结 4 1006
栀梦
栀梦 2021-01-07 16:34

How I can set a header in the webClient class? I tried:

client.Headers[\"Content-Type\"] = \"image/jpeg\";

that throws a

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-07 17:02

    It seems you can not set Content-type with WebClient.UploadValues method. You could set Content-type with WebClient.UploadData method

    Use something like,

    Client.Headers["Content-Type"] = "application/json";
    Client.UploadData("http://www.imageshack.us/upload_api.php", "POST", Encoding.Default.GetBytes("{\"Data\": \"Test\"}"));
    

提交回复
热议问题