C#调用webapi,提示url不正确

-一个大坑 2017-06-30 04:42:19

public void WebApi()
{
string url = "http://api.jisuapi.com/iqa/query";
string param = "appkey=633b01074279fa63&question=杭州天气";
string result = request(url,param);
}

/// <summary>
/// 发送HTTP请求
/// </summary>
/// <param name="url">请求的URL</param>
/// <param name="param">请求的参数</param>
/// <returns>请求结果</returns>
public static string request(string url, string param)
{
string strURL = url + '?' + param;
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
request.Method = "POST";
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
string StrDate = "";
string strValue = "";
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
while ((StrDate = Reader.ReadLine()) != null)
{
strValue += StrDate + "\r\n";
}
return strValue;
}

这个可以正确访问,也有返回值

string url = "*****/QueryMileage";
string param = "param = { \"regNO\":[\"粤T123456\"],\"begin\":\"2017-06-24 09:30:00\",\"end\":\"2017-06-24 14:29:15\"}";
这样就提示url不正确
...全文
291 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
-一个大坑 2017-07-01
  • 打赏
  • 举报
回复
引用 2 楼 sp1234 的回复:
你的两个 param 例子根本不是同一类,看不出来?后一个写法有什么实际根据吗?
看着都一样呀,前面网址,后面传参
  • 打赏
  • 举报
回复
你的两个 param 例子根本不是同一类,看不出来?后一个写法有什么实际根据吗?
-一个大坑 2017-07-01
  • 打赏
  • 举报
回复

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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