我正在开发一些用于测试的 API,当我发出网络请求时,尤其是当我检索网络响应时,我遇到了问题。我使用这段代码:
字符串请求 = HttpPost(" http://iunlocker.net/check_imei.php ", "ime_i=013270000134001");
public static string HttpPost(string URI, string Parameters)
{
try
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
System.Net.WebResponse resp= req.GetResponse();
if (resp == null) return null;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}
catch (Exception ex) { }
return null;
}
通话中的网站就是一个例子,因为有了这个网站和其他网站,我无法正确检索结果。我收到异常“错误 403”
谁能告诉我我可能做错了什么来帮助我?
我认为问题出在编码/解码上——实际上使用 Fiddler 它会在查看文本之前询问我是否要解码——但是对于另一个网站,例如,我从 Fiddler 收到相同的消息,但我可以检索响应没有问题。
提前致谢。