2017-07-19 1 views
0

私はPOSTは、ApacheのHttpClientをを使用して、以下の(eBayのAPIアプリケーショントークン要求)を送信しようとしている、と私は保ちます400:Bad Requestエラーが発生しました。ここで私はeBayのAPIの400不正な要求を取得していると私は理解できない理由

はコードです:

import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.entity.UrlEncodedFormEntity; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.impl.client.CloseableHttpClient; 

import org.apache.http.message.BasicNameValuePair; 
import sun.misc.BASE64Encoder; 

import java.io.BufferedReader; 

import java.util.ArrayList; 
import java.util.List; 

public class OrderFileDownload { 

    public static void main(String[] args) throws Exception { 
      OrderFileDownload od = new OrderFileDownload(); 
      System.out.println(od.submitTokenRequest()); 
    } 

    public String submitTokenRequest() throws Exception { 
     String url = "https://api.sandbox.ebay.com/identity/v1/oauth2/token"; 
     CloseableHttpClient client = HttpClients.createDefault(); 

     List<BasicNameValuePair> params = new ArrayList<>(); 
     params.add(new BasicNameValuePair("grant_type","client_credentials")); 
     params.add(new BasicNameValuePair("redirect_uri","<RuRedirect-value>")); 
     params.add(new BasicNameValuePair("scope","https://api.ebay.com/oauth/api_scope")); 

     HttpPost request = new HttpPost(url); 
     request.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
     request.addHeader("Authorization","Basic " + encrypt64("<Client-Id>:<ClientSecret>")); 

     HttpEntity entity = new UrlEncodedFormEntity(params); 
     request.setEntity(entity); 

     HttpResponse response = client.execute(request); 
     client.close(); 

     return response.toString(); 
    } 

    private String encrypt64(String text) { 
     BASE64Encoder enc = new BASE64Encoder(); 
     return enc.encode(text.getBytes()); 
    } 
} 

これは、メソッドが返すレスポンスです:

HttpResponseProxy{HTTP/1.1 400 Bad Request [Content-Type: text/plain, Content-Length: 0] [Content-Type: text/plain,Content-Length: 0,Chunked: false]} 

誰も私がこれを把握助けてくださいことはできますか?

ありがとうございました!

答えて

0

ebay APIを使用しているときに同じ問題に直面しましたが、1分後に試行しようとするコードに再試行を追加すると、それは私のために働きます。

これも試してみることができますが、私はそれの根本的な原因をまだ見つけていません。

おかげで、

Parminderシン

関連する問題