java - API call by HTTP POST method without using parameter name for the body -
i'm using java. how can create http post phone call api , inform in body "json" value (without parameter name)?
per illustration phone call url: https://api.nimble.com/api/v1/contact?access_token=12123486db0552de35ec6daa0cc836b0 (post method) , in body have (without parameter name):
{'fields':{'first name': [{'value': 'jack','modifier': '',}],'last name': [{'value': 'daniels','modifier': '',}],'phone': [{'modifier': 'work','value': '123123123',}, {'modifier':'work','value': '2222',}],},'type': 'person','tags': 'our customers\,best'}
if correct, give me illustration please?
using library network part : http://hc.apache.org/
using library json part : http://code.google.com/p/google-gson/
example :
public string examplepost(dataobject data) { httpclient httpclient = new defaulthttpclient(); seek { httppost httppost = new httppost("your url"); // serialization of info json gson gson = new gsonbuilder().serializenulls().create(); string json = gson.tojson(data); httppost.addheader("content-type", "application/json"); // creating entity send bytearrayentity tosend = new bytearrayentity(json.getbytes()); httppost.setentity(tosend); httpresponse response = httpclient.execute(httppost); string status = "" + response.getstatusline(); system.out.println(status); httpentity entity = response.getentity(); inputstream input = entity.getcontent(); stringwriter author = new stringwriter(); ioutils.copy(input, writer, "utf8"); string content = writer.tostring(); // useful content system.out.println(content); writer.close(); entityutils.consume(entity); } grab (exception e) { e.printstacktrace(); homecoming null; } { httpclient.getconnectionmanager().shutdown(); } }
hope helps.
java api http post nimble
No comments:
Post a Comment