简体   繁体   English

HTTP请求未获得响应

[英]HTTP Request Not Getting Response

I'm trying to send an HTTP request to of the form : 我正在尝试将HTTP请求发送到的形式:

GET /api/content/v1/parser?url=http://blog.readability.com/2011/02/step-up-be-heard-readability-ideas/&token=1b830931777ac7c2ac954e9f0d67df437175e66e

The website I'm trying to communicate with is www.readability.com 我要与之交流的网站是www.readability.com

I've been trying to use the following request: 我一直在尝试使用以下请求:

string readabilityUrl = "http://www.readability.com";
string requestUrl = createRequestUrl(articleUrl);

// Create http request send to readability api
System.Diagnostics.Debug.WriteLine(readabilityUrl + requestUrl);

var request = (HttpWebRequest)WebRequest.Create(readabilityUrl);
var postData = requestUrl;
var postReqData = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";

using (var stream = request.GetRequestStream())
{
    stream.Write(postReqData, 0, postReqData.Length);
}

var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

System.Diagnostics.Debug.WriteLine(responseString);

But all it does is getting the html content of www.readaility.com instead of returning the relevant data I actually need. 但它所做的只是获取www.readaility.com的html内容,而不是返回我实际需要的相关数据。

I guess I don't send the right parameters and I'd be thankful if you could help me out and point me to the solution. 我想我没有发送正确的参数,如果您能帮助我并指出解决方案,我将不胜感激。

  1. Check if you are getting HTML because you are being redirected from your target (HTTP 302). 检查是否由于从目标(HTTP 302)重定向而获取HTML。 Check the content you are getting, maybe it contains an error about lacking credentials or that the resource does not exist. 检查您得到的内容,可能包含有关缺少凭据的错误或资源不存在的错误。

  2. Note you are creating a POST request, but the example you put at the beginning is a GET request. 请注意,您正在创建POST请求,但是您放在开头的示例是GET请求。

  3. You should encode the url you are using as parameter with HttpUtility.UrlEncode(url) 您应该使用HttpUtility.UrlEncode(url)用作参数的url进行编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM