Note that there are some explanatory texts on larger screens.

plurals
  1. POSend data from android to web api service
    primarykey
    data
    text
    <p>I have a problem in my android Background service. While send the data using http protocol it shows <strong>ClientProtocolException</strong> </p> <p>My WebAPI is</p> <pre><code> [AcceptVerbs("GET", "POST")] [ActionName("InsertLocationDetails")] public string InsertLocationDetails([FromBody]LocationDetails locDetails ) { return objLocationService.InsertLocationDetails(locDetails.UserId,locDetails.DateTime.ToString(), locDetails.Latitude,locDetails.Longitude,locDetails.Status.ToString(),locDetails.Location.ToString()); } </code></pre> <p>I have my LocationDetails class with paramaters</p> <pre><code> public class LocationDetails { public int UserId { get; set; } public Double Latitude { get; set; } public Double Longitude { get; set; } public string Status { get; set; } public string DateTime { get; set; } public string Location { get; set; } } </code></pre> <p>In my Android background code i m using http protocol. I need to communicate with my web api service to insert the datas</p> <pre><code> public String insertLocationDetails(int userid,String newtime,String status,double latitude,double longitude,String address,String city,String country) { HostUrl="http://URL/ServiceName/InsertLocationDetails"; HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(HostUrl); try { List&lt;NameValuePair&gt; params = new LinkedList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("UserId",String.valueOf(userid))); params.add(new BasicNameValuePair("DateTime", newtime)); params.add(new BasicNameValuePair("Latitude",String.valueOf(latitude))); params.add(new BasicNameValuePair("Longitude",String.valueOf(longitude))); params.add(new BasicNameValuePair("Status",status)); params.add(new BasicNameValuePair("Location",(address+","+city+","+country))); httpPost.setHeader("Content-Type", "application/json"); httpPost.setHeader("Accept", "application/json"); HttpEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); httpPost.setEntity(entity); ResponseHandler&lt;String&gt; handler = new BasicResponseHandler(); result =httpClient.execute(httpPost,handler); } catch (ClientProtocolException e) { e.printStackTrace(); Log.e(TAG, "ClientProtocolException in callWebService(). " + e.getMessage()); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, "IOException in callWebService(). " + e.getMessage()); } return result; }} </code></pre> <p>Actually my jquery code is working properly and inserting values </p> <p><strong>My Javascript code is working properly</strong></p> <pre><code>function insertLocationDetails() { var url=serverUrl(); var urlpath={ UserId : userid, DateTime : datetime, Latitude: latitude, Longitude : longitude, Status: status, Location : address }; $.ajax ({ cache: false, async: true, type: "POST", dataType: "json", contentType: "application/json;charset=utf-8", url: url +"InsertLocationDetails", data: JSON.stringify(urlpath), success: function (result) { var result = eval(result); for (var property in result) { } } }); } </code></pre> <p>Kindly help me figure out the Exception in my Android Background service please give a correct code to make communication with my service</p> <p>Thanks in advance ARUN</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload