I trying to make http – post call.
The server that i send him this request need to have two parameters
1. first parameter is Int
2. second parameter is enum that i sending as string
I try to do it in two ways and them both fail:
First way:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("intVal", "-100"));
nameValuePairs.add(new BasicNameValuePair("enumVal", "enumAsString"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
I get ‘bar request’ as a response.
Second way:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(SERVER_ADDRESS + METHOD_NAME);
try
{
HttpParams postParams = new BasicHttpParams();
postParams.setIntParameter("intVal", -100 );
postParams.setParameter ("enumVal" , "enumAsString" );
httppost.setParams(postParams);
HttpResponse p = httpclient.execute(httppost);
}
catch(Exception e)
{
....
}
In this way i see that the server get the parameters – but the first parameter ( that need to be int ) is 0 and the second parameter ( that need to be enum ) is 0 also.
P.S : The code that run on the server is WCF code – using REST.
Please .. i must solve this issue …
Thanks.
Here is two different ways which you can send param with
HttpPostandHttpUrlConnectionusing Andorid :First Way :
The second way is :
The both ways are working properly.