[英]I'm getting a 400 Bad Request on the Ebay API and I can't figure out why
我正在嘗試使用Apache的HttpClient發送以下(ebay API應用程序令牌請求) POST ,盡管我的代碼看起來不錯,但我仍然不斷收到400:Bad Request錯誤。
這是代碼:
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]}
誰能幫我解決這個問題?
謝謝!
我在使用ebay API時遇到了同樣的問題,但是如果我在代碼中添加了retry,嘗試在幾分鍾后嘗試,那么它對我有用。
您也可以嘗試此操作,但我尚未找到其根本原因。
謝謝,
Parminder Singh
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.