Passing this URL to my httpget is returning null. Tried every way

可紊 提交于 2019-12-13 20:58:10

问题


I have been trying for hour every possible method on this forum but no luck. PLEASSE help I have the following server url

String url = "http://namara.io/api/v0/resources/fef59c15-852f-4f4b-aaef-c9475b3d17c6/data?where=%7b%22column%22:3,%22selector%22:%22eq%22,%22value%22:%22Sercan%22%7d"

Here is my code:

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response;
try {
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
.
.
.

However i am always getting null values. When I check the StatusLineReturned code, it is saying error 401: Uauthorized.

I have no idea what is it that I am doing wrong? Why it won't just work!


回答1:


Posting an answer from comments:

If you'll try to open it in browser, it says the same, so you need to authorize at first. Per docs at namara.io, you have to provide api_key.




回答2:


just out of curriousity : can u try

URL u = new URL(youurl);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);

if it doesnt work , maybe you need to use a post not get method



来源:https://stackoverflow.com/questions/22112274/passing-this-url-to-my-httpget-is-returning-null-tried-every-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!