通过JSON对象RESTful Web服务的URL中的Android? [英] passing JSON object in URL of RESTFUL Web service in Android?
问题描述
我用JSON的REST Web serivces,我必须通过JSON对象中的服务URL工作。我已经成功创建了JSON对象,但得到异常时,我的网址创建与服务器的HTTP连接。
下面我不得不提到我的网址:
http://72.5.167.50:8084/UpdateProfileInfo?{"ProfileEditId":"917","ContactsEmail":[{"Email":"dsfs","ContactId":""}],"ContactsPhone":[{"CountryId":"+1","Type":"2","Phone":"345345"}],"ProfileId":"290","LastName":"demo","GroupId":"1212","Title":"sdf","City":"dsf","TemplateId":"1212","State":"dsf","Auth$c$c":"9bcc6f63-2050-4c5b-ba44-b8103fbc377a","Address":"sdf","FirstName":"demo","ContactId":"","Zip":"23","Company":"tv"}
获得 java.lang.IllegalArgumentException:如果非法字符在code查询
:
INT TIMEOUT_MILLISEC = 100000; // 1000 milisec =1秒
INT SOCKET_TIMEOUT_MILISEC = 120000; //2分钟
的HttpParams的HttpParams =新BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(的HttpParams,TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(的HttpParams,SOCKET_TIMEOUT_MILISEC);
HttpClient的客户端=新DefaultHttpClient(的HttpParams);
HttpPost请求=新HttpPost(URL);
HTT presponse响应= client.execute(要求);
responseString =请求(响应);
请建议我,如果我做错了什么与我的网址。
*的编辑:的*试图用钥匙仍然得到Exeception:
<$p$p><$c$c>http://72.5.167.50:8084/UpdateProfileInfo?profileinof={"ProfileEditId":"917","ContactsEmail":[{"Email":"sdf","ContactId":""}],"ContactsPhone":[{"CountryId":"+1","Type":"2","Phone":"345345345"}],"ProfileId":"290","LastName":"demo","GroupId":"1212","Title":"dsf","City":"dsf","TemplateId":"1212","State":"dsf","Auth$c$c":"d968273a-0110-461b-8ecf-3f9c456d17ac","Address":"dsf","FirstName":"demo","ContactId":"","Zip":"23","Company":"tv"}
目前,我们需要做的这种要求不同的HTTP请求的格式。
我有提到我下面的code这一点。
公开的JSONObject getJSONObject(){
返回jsonObj;
}
上面的方法我会返回一个JSON字符串被传递在下面的方法。
公共静态的Htt presponse makeRequest(字符串URL)抛出异常
{
// HttpClient的实例,使申请
DefaultHttpClient的HttpClient =新DefaultHttpClient();
// URL的POST数据
HttpPost httpost =新HttpPost(URL);
//转换参数成JSON对象
的JSONObject支架= getJSONObject();
//将结果传递给一个字符串生成器/实体
StringEntity本身=新StringEntity(holder.toString());
//设置POST请求的结果字符串
httpost.setEntity(SE);
httpost.setHeader(接受,应用/ JSON);
httpost.setHeader(内容型,应用/ JSON);
//手柄什么从页返回的
ResponseHandler的ResponseHandler的=新BasicResponseHandler();
返回httpclient.execute(httpost,ResponseHandler所);
}
堆栈后帮我做这个任务...!
I am working with JSON Restful web serivces where I have to pass JSON object in the Service URL. I have created the JSON object successfully but getting exception when my URL created the HTTP connection with the SERVER.
Below I have mention my URL:
http://72.5.167.50:8084/UpdateProfileInfo?{"ProfileEditId":"917","ContactsEmail":[{"Email":"dsfs","ContactId":""}],"ContactsPhone":[{"CountryId":"+1","Type":"2","Phone":"345345"}],"ProfileId":"290","LastName":"demo","GroupId":"1212","Title":"sdf","City":"dsf","TemplateId":"1212","State":"dsf","AuthCode":"9bcc6f63-2050-4c5b-ba44-b8103fbc377a","Address":"sdf","FirstName":"demo","ContactId":"","Zip":"23","Company":"tv"}
Getting java.lang.IllegalArgumentException: Illegal character in query
in code :
int TIMEOUT_MILLISEC = 100000; // 1000 milisec = 1 seconds
int SOCKET_TIMEOUT_MILISEC = 120000; // 2 minutes
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, SOCKET_TIMEOUT_MILISEC);
HttpClient client = new DefaultHttpClient(httpParams);
HttpPost request = new HttpPost(url);
HttpResponse response = client.execute(request);
responseString = request(response);
Please suggest me If I am doing something wrong with my URL.
*EDITED:*Tried with a key still getting Exeception:
http://72.5.167.50:8084/UpdateProfileInfo?profileinof={"ProfileEditId":"917","ContactsEmail":[{"Email":"sdf","ContactId":""}],"ContactsPhone":[{"CountryId":"+1","Type":"2","Phone":"345345345"}],"ProfileId":"290","LastName":"demo","GroupId":"1212","Title":"dsf","City":"dsf","TemplateId":"1212","State":"dsf","AuthCode":"d968273a-0110-461b-8ecf-3f9c456d17ac","Address":"dsf","FirstName":"demo","ContactId":"","Zip":"23","Company":"tv"}
There is different format of HTTP request that we needed to make for this kind of REQUEST.
I have mention my code below for this.
public JSONObject getJSONObject(){
return jsonObj;
}
ABove method returns me a JSON String which is passed in the below method.
public static HttpResponse makeRequest(String url) throws Exception
{
//instantiates httpclient to make request
DefaultHttpClient httpclient = new DefaultHttpClient();
//url with the post data
HttpPost httpost = new HttpPost(url);
//convert parameters into JSON object
JSONObject holder = getJSONObject();
//passes the results to a string builder/entity
StringEntity se = new StringEntity(holder.toString());
//sets the post request as the resulting string
httpost.setEntity(se);
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
//Handles what is returned from the page
ResponseHandler responseHandler = new BasicResponseHandler();
return httpclient.execute(httpost, responseHandler);
}
Stack post helped me for doing this task...!!!
这篇关于通过JSON对象RESTful Web服务的URL中的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!