I have this URL (which executes in a browser fine):
https://api-test.company.com/contacts/?q=email=jlowder@company.com
which I am trying to use HttpClient to execute. I’ve tried:
String URL = "https://api-test.company.com/contacts?q=" + URLEncoder.encode("email=jlowder@company.com");
DefaultHttpClient client = new DefaultHttpClient();
HttpGet c = new HttpGet(URL);
HttpResponse response = client.execute(c);
String resultContent = myRestCall.GetResponseText(response);
This returns the error:
QUERY_PARAMunable to parse query string ’email=jlowder@company.com’
And I’ve tried:
GetMethod method = new GetMethod("https://api-test.company.com/contacts/?q=");
method.setQueryString(new NameValuePair[] {new NameValuePair("email", "jlowder@company.com")});
HttpGet c = new HttpGet(method.toString());
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(c);
Which returns:
java.lang.IllegalStateException: Target host must not be null, or set in parameters.
So how exactly do I correctly parse this simple GET request?
Thanks.
In your example, you still have an parameter q which should be passed, too. Normaly, you have key/values. Why do you have such a constellation?
?q=email=jlowder@company.com
There is a value for “q” missing. Or do you want to set “email=jlowder@company.com” as value for “q” Then you should escape the “=”