简体   繁体   中英

how to send cURL in Android to REST service

I'm newbie in android, I want to get some data from my REST service, but I have some problem to initialize the method what's I send into the my REST service. you know that REST service using cURL to manipulate some data(POST,PUT,GET,DELETE). now how to send POST PUT GET DELETE method via cURL in android. do same as using httppost to send it? or how to send cURL to rest service in android?

Using HttpClient you can send POST,PUT,GET,DELETE requests. For an example POST request check here .

public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");

try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("id", "12345"));
    nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
} catch (IOException e) {
    // TODO Auto-generated catch block
}
} 

// Newventuresmarket.com // Steven Koelsche` Thanks Brak. Mars you might need to adjust headers also if needed for cURL...

try {
        httppost.setHeader("Content-Type", "application/json");
        httppost.setHeader("Accept", "application/json");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM