昨天我能够从get请求中获取数据,但是今天如果我调用相同的api,我会得到
java.io.FileNotFoundException: https://api.quikr.com/jobs/v1/zwayam/application?companyName=test&jobId=123
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at com.zwayam.controller.QuikrDataPoint.getJobApplicationForQuikrJobs(QuikrDataPoint.java:162)
at com.zwayam.controller.QuikrDataPoint.main(QuikrDataPoint.java:54)
引起:java.io.FileNotFoundException:https://api.quikr.com/jobs/v1/zwayam/application?companyName=test&jobId=123 at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at java.net.HttpURLConnection.getResponseCode(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source) 在com.zwayam.controller.QuikrDataPoint.getJobApplicationForQuikrJobs(QuikrDataPoint.java:159) ......还有1个
我无法直接在浏览器中访问此API,因为有一些应用程序标头要设置 这是编码问题还是api问题?
String urlstr = "https://api.quikr.com/jobs/v1/zwayam/application?";
List<NameValuePair> params = new LinkedList<NameValuePair>();
params.add(new BasicNameValuePair("companyName", "test"));
params.add(new BasicNameValuePair("jobId", "123"));
String paramString = URLEncodedUtils.format(params, "utf-8");
url = new URL(urlstr + paramString);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setRequestProperty("Accept", "application/json");
System.setProperty("http.agent", "");
Calendar cal = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd");
String todaysDate = format.format(cal.getTime());
String emailId = "roshan@zwayam.com";
String data = appId + emailId + todaysDate;
SecretKeySpec signingKey = new SecretKeySpec(tokenKey.getBytes(), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
String signature = toHexString(mac.doFinal(data.getBytes()));
connection.setRequestProperty("Content-Type", "application/JSON");
connection.setRequestProperty("X-Quikr-App-Id", "890");
connection.setRequestProperty("X-Quikr-Token-Id", tokenId.toString());
connection.setRequestProperty("X-Quikr-Signature-v2", signature);
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
int responseCode = connection.getResponseCode();
这是调用api的部分,我得到的响应代码是404
答案 0 :(得分:0)
问题在于api,他们修复了它,现在工作正常:)