To do a project, you need to upload the user's message to the server.
I'm using HttpGet request, the message content directly spliced in the url above.
When will throw However, when the intermediate message content appears blank, execution HttpGet get = new HttpGet (url) statement exception: IllegalArgumentException
Great God ask you this how do ah?
Reply:
Their top!
Reply:
It seems unlikely that url parameter spaces Spaces can be used to handle the specified parameters URLEncoder.encode
Reply:
decode ah
Reply:
HttpGet get = new HttpGet (URLEncoder.encode (url, "UTF-8"));
Reply:
The how Encode it? Is the entire url into them yet? I just tried it, something like this:
(To maintain secrecy, I put the URL replaced baidu)
String url = "http://baidu.com?name=han&content=hello world";
HttpGet get = new HttpGet (URLEncoder.encode (url, "UTF-8"));
Then reported the anomaly:
java.lang.IllegalStateException:. Target host must not be null, or set in parameters scheme = null, host = null, path = http://baidu.com?name=han&content=hello world
Is not the whole url should not give Encode, ah? If only Encode behind the request, then the statement, and then how and in front of http://baidu.com fight together?
Reply:
URLEncoder.encode (). This method of all non-alphanumeric characters changed to% sequence (in addition to spaces, underscores, hyphens, dots and asterisks), if the entire url to encode it, =, & these characters will be encoded . So the best part of the coding-by.
String query = URLEncode.encode ("name");
query + = "=";
query + = URLEncode.encode ("han");
query + = "&";
query + = URLEncode.encode ("content");
query + = "=";
query + = URLEncode.encode ("hello world");
String url = "? Http://baidu.com" + query;
Reply:
I say deal with the meaning of the text specified parameters can be used to understand the best processing parameters is only possible space processing parameters
Reply:
For example http://baidu.com?name=han&content=hello world then this treatment
url = "http://baidu.com?name=han&content =" + URLEncoder.encode ("hello world", "utf-8");
Reply:
Why not post? get the url length is limited, can not take many words
Reply:
Above have made it very clear.
Reply:
Ah, I see, that's a little bit complicated to write ~ ~ Thank you!

Reply:
php provided is get

Reply:
8th Floor, positive solution to solve my problem ..... praise.
No comments:
Post a Comment