c#post头问题

刳比 2015-11-05 10:03:04
POST /hospital/hospitalsearch/list.json HTTP/1.1
User-Agent: android
version: 2.34
appid: p_android_weiyi
version-type: patient
os-token-id: 7c5280e3-23cf-466b-afad-d8d6edb87f4a
sign: UzzEyNJMwZlhR7pet6Swt0SxhQFxVcsqLFhki1MN4uWLoeKnCl5gIxpb3dwgK1v5MLLTaSwSsGWsodbJn5/GMaHhOUf6Wk7T3hJIei+Qm+VWQ/V2fv0VbEjl4ijKI+Fgh7JslaLDvI5CP9PONBEV6I/9iVzkGD1OGSOAHYNcT5g=
Content-Type: application/json
Content-Length: 71
Host: mobileservice.guahao.cn
Connection: Keep-Alive
Expect: 100-continue

{"pageNo":1,"pageSize":20,"sort":"region_sort","area":"79","haoyuan":2}


c#代码
string strUrl = "http://mobileservice.guahao.cn/hospital/hospitalsearch/list.json";
HttpWebRequest httpWebRequest = null;
HttpWebResponse httpWebRespones = null;
string strHtml;
httpWebRequest = (HttpWebRequest)WebRequest.Create(strUrl);
httpWebRequest.AllowAutoRedirect = true;
httpWebRequest.UserAgent = "android";
httpWebRequest.Method = "post";
httpWebRequest.KeepAlive = true;
httpWebRequest.AllowAutoRedirect = false;
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add("version", "2.34");
httpWebRequest.Headers.Add("appid", "p_android_weiyi");
httpWebRequest.Headers.Add("version-type", "patient");
httpWebRequest.Headers.Add("sign", "UzzEyNJMwZlhR7pet6Swt0SxhQFxVcsqLFhki1MN4uWLoeKnCl5gIxpb3dwgK1v5MLLTaSwSsGWsodbJn5/GMaHhOUf6Wk7T3hJIei+Qm+VWQ/V2fv0VbEjl4ijKI+Fgh7JslaLDvI5CP9PONBEV6I/9iVzkGD1OGSOAHYNcT5g=");

string postDataStr = @"{""pageNo"":1,""pageSize"":10,""sort"":""department"",""department"":""2b7ac3ed-6cad-4307-93a4-1b111c5e182e000"",""dynamicFilter"":1}";
byte[] postdatabytes = Encoding.UTF8.GetBytes(postDataStr);
Stream writer;
writer = httpWebRequest.GetRequestStream();
writer.Write(postdatabytes, 0, postdatabytes.Length);
writer.Flush();
writer.Close();

httpWebRespones = (HttpWebResponse)httpWebRequest.GetResponse();

using (Stream stream = httpWebRespones.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
strHtml = reader.ReadToEnd();
}
}

麻烦看下是否头信息不对,我用php试过是可以访问的
...全文
178 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
刳比 2015-11-05
  • 打赏
  • 举报
回复
是我提交的数据问题,还是版主细心,谢谢两位的解答,刚忘了给后面这位兄弟分了,可以追加分的吗?
xdashewan 2015-11-05
  • 打赏
  • 举报
回复
引用 4 楼 cq5811809 的回复:
我对比了我两边的签名信息,完全一样,和我抓包抓的一模一样,为什么php可以c#不行呢,这里难道对方可以判断我是c#提交的还是php提交的?
用抓包工具看一下PHP和C#发出的请求全比较一下,包括头部和Content部分
刳比 2015-11-05
  • 打赏
  • 举报
回复
我对比了我两边的签名信息,完全一样,和我抓包抓的一模一样,为什么php可以c#不行呢,这里难道对方可以判断我是c#提交的还是php提交的?
xdashewan 2015-11-05
  • 打赏
  • 举报
回复
签名是通过算法算出来,里面可能带有时间戳,所以你得产生和你php相同的签名
刳比 2015-11-05
  • 打赏
  • 举报
回复
他返回的信息是签名错误,签名是这个sign信息
bdmh 2015-11-05
  • 打赏
  • 举报
回复
http头应该没问题,关键的是你post的参数是否正确,这个你要跟后台一起调试一下

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧