HttpWebRequest - 有效负载错误

时间:2016-05-27 14:49:29

标签: c# httpwebrequest

HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url);
Request.Headers.Add("Authorization", "OAuth " + GetAccessTokenBeta());
Request.Proxy.Credentials = CredentialCache.DefaultCredentials;
Request.Method = "POST";
Request.ContentType = "application/xml";

using (var streamWriter = new StreamWriter(Request.GetRequestStream()))
{
    string xml = getXml(tabletype, values.ToArray());
    streamWriter.Write(xml);
    streamWriter.Flush();
    streamWriter.Close();
}

try
{
    using (WebResponse response = Request.GetResponse())
    {
        using (StreamReader rd = new StreamReader(response.GetResponseStream()))
        {

        }
    }
}
catch (WebException ex)
{
    var resp = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
    Core.ShowError("Error connecting to the webservice." + "\r\n" + resp);
}

我已经确认端点和XML使用Postman工作,但我在C#中遇到了这个问题。

发送HTTP请求时出错。消息有效内容的类型为:BufferInputStream

0 个答案:

没有答案