我有這個問題發送HTTP POST來點網的WebAPI
正與獲取
我想送一個HTTP POST
這裏是我的機器人類,並請求方法
public static String readUrl(String url, ArrayList<NameValuePair> params) {
try {
HttpClient client = new DefaultHttpClient();
HttpPost method = new HttpPost(url);
if (params != null) {
method.setEntity(new UrlEncodedFormEntity(params));
}
HttpResponse response = client.execute(method);
InputStream inputStream = response.getEntity().getContent();
String result = convertInputStreamToString(inputStream);
return result;
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
和第是爲請求碼
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("region","1"));
params.add(new BasicNameValuePair("area","1"));
params.add(new BasicNameValuePair("sector","1"));
params.add(new BasicNameValuePair("address",edtReqAddres.getText().toString()));
params.add(new BasicNameValuePair("mobile",edtMobileNumber.getText().toString()));
params.add(new BasicNameValuePair("username","test"));
params.add(new BasicNameValuePair("message", edtSubject.getText().toString()));
params.add(new BasicNameValuePair("compid","0"));
params.add(new BasicNameValuePair("geo","1"));
text = webservice.readUrl("http://192.168.1.102:81/api/products", params);
而且這是我的結果 :(
{ 「消息」: 「沒有HTTP資源發現,請求URI 'http://192.168.1.102:81/api/products' 相匹配。」}
這是我的WebAPI(DOTNET的)
[System.Web.Http.AcceptVerbs("GET", "POST")]
public string GetProductById(int region, int area, int sector, string address, string mobile, string username, string message, int compid, string geo)
{
fddService.mobService service=new mobService();
return service.NewMessage(region, area, sector, address, mobile, "", message, compid, "");
}
尚未配置您的服務器來處理'/ API/products'請求。 – Breavyn
嗯我是新的web api你是什麼意思@ColinGillespie請解釋更多 –
我可以通過獲取@ColinGillespie –