4

我正在尝试从 Windows Phone 应用程序的公共 API 收集数据。

private void GatherPosts()
{
    string url = baseURL + "?after=" + lastPostId + "&gifs=1";
    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
    request.ContentType = "text/json";
    request.Method = "GET";

    AsyncCallback callback = new AsyncCallback(PostRequestFinished);
    request.BeginGetResponse(callback, request);
}

private void PostRequestFinished(IAsyncResult result)
{
    HttpWebRequest request = (HttpWebRequest)result.AsyncState;
    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
}

ProtocolViolationException但是我一直在回调方法的最后一行收到消息A request with this method cannot have a request body.。我读到这是因为我正在尝试发送数据,这显然是 GET 协议禁止的,但我不知道我在哪里做,即如何避免它。

4

1 回答 1

8

这可能是ContentType它认为有一个请求正文,因此是例外。

你会想要设置Accept-Encoding

于 2013-05-13T16:41:40.803 回答