我正在尝试使用参数调用Web服务(asmx),但始终收到“缺少参数:Lane”响应。下面的代码是我正在使用的
final HttpClient Client = new DefaultHttpClient();
String jsonstring = "",step = "0";
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Lane","1"));
params.add(new BasicNameValuePair("Name","Test test"));
HttpPost httppostreq = new HttpPost(url);
httppostreq.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpresponse = Client.execute(httppostreq);
jsonstring = EntityUtils.toString(httpresponse.getEntity());
当我在标题中添加参数并设置“内容类型:application / x-www-form-urlencoded”时,我可以使用邮递员来调用Web服务,但不能使其在Android Studio中工作
这是我的网络服务中的代码:
[WebMethod]
public void MyTestService(string Lane,string Name)
{
Dictionary<string,object> parameter = new Dictionary<string,object>();
parameter.Add("@lane",Lane);
parameter.Add("@name",Name);
DataSet dt = Dataaccess.executeStoreProcedureDataSet("sp_GetLaneName",parameter);
string jsonReturned = JsonConvert.SerializeObject(dt,Formatting.Indented);
Context.response.contenttype = "text/plain; charset=UTF-8";
Context.Response.Write(jsonReturned);
}