尝试执行GET Web申请,但未处理ProtocolViolationException

时间:2019-04-16 20:53:21

标签: c# get httpwebrequest http-method

我正在尝试进行Web申请,并且我无法使用POST,因为de Web Service期望GET来提供参数。但是我收到以下协议违规错误:

var streamWriter = new StreamWriter(wReq.GetRequestStream()

有人可以帮我吗?

WebRequest wReq = HttpWebRequest.Create(InfoBipLogURL);
wReq.Method = "GET";
wReq.Headers["Authorization"] = "Basic " + TokenAutorizacaoInfoBip;
wReq.Headers["Cookie"] = Cookie_Aut;
wReq.ContentType = "application/json";

using (var streamWriter = new StreamWriter(wReq.GetRequestStream()))
{
    streamWriter.Write(objLog.ToJsonString());
    streamWriter.Flush();
    streamWriter.Close();
}

using (var resposta = wReq.GetResponse() as HttpWebResponse)
{
    var streamDados = resposta.GetResponseStream();
    StreamReader reader = new StreamReader(streamDados);
    object objResponse = reader.ReadToEnd();
    var retornoLog = JsonConvert.DeserializeObject<RetornoLog>(objResponse.ToString());
    streamDados.Close();
    resposta.Close();
    return retornoLog;
}

0 个答案:

没有答案