Android HttpPost返回与浏览器不同的json字符串
当我去 我收到一个包含良好数据的json 即Android HttpPost返回与浏览器不同的json字符串,android,json,post,https,Android,Json,Post,Https,当我去 我收到一个包含良好数据的json 即 [ { "url": "https://api.github.com/gists/5143977", "forks_url": "https://api.github.com/gists/5143977/forks", "commits_url": "https://api.github.com/gists/5143977/commits", "id": "5143977", etc. 但如果我读到的地
[
{
"url": "https://api.github.com/gists/5143977",
"forks_url": "https://api.github.com/gists/5143977/forks",
"commits_url": "https://api.github.com/gists/5143977/commits",
"id": "5143977",
etc.
但如果我读到的地址与此代码相同:
String jsonString = null;
InputStream is = null;
HttpResponse response = null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://api.github.com/users/jkirkell/gists");
response = httpclient.execute(httppost);
}catch(Exception e){
throw e;
}
我收到这个json字符串:
{"message":"Not Found"}
我的代码出了什么问题?是
Get
请求,但您正在使用HTTP post
试着这样读
int k=0
URL url = new URL(yoururl);
InputStream input=url1.openStream();
BufferedInputStream bis=new BufferedInputStream(input);
ByteArrayBuffer baf=new ByteArrayBuffer(1000);
while((k=bis.read())!=-1)
{
baf.append((byte)k);
}
String data=new String(baf.toByteArray());
它是
Get
请求,但您正在使用HTTP post
试着这样读
int k=0
URL url = new URL(yoururl);
InputStream input=url1.openStream();
BufferedInputStream bis=new BufferedInputStream(input);
ByteArrayBuffer baf=new ByteArrayBuffer(1000);
while((k=bis.read())!=-1)
{
baf.append((byte)k);
}
String data=new String(baf.toByteArray());
您应该使用
HttpGet
而不是HttpPost
:
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet("https://api.github.com/users/jkirkell/gists");
response = httpclient.execute(request);
您应该使用
HttpGet
而不是HttpPost
:
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet("https://api.github.com/users/jkirkell/gists");
response = httpclient.execute(request);