0
這是我的unsplash API 的HTTP請求代碼在瀏覽器中,但在Java中的HTTP請求打開時,HTTP成功運行,我有這個問題java.io.FileNotFoundException爲unsplash API
我怎麼能解決這個問題
注:此代碼與Instagram的API成功運行
new Thread() {
@Override
public void run() {
Log.i("ttttttrrrraaaaiiiinnn", "Getting access token");
try {
URL url = new URL("https://api.unsplash.com/photos?client_id=***");
Log.i("", "Send GET url liked image" + url.toString());
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoInput(true);
OutputStreamWriter writer = new OutputStreamWriter(
urlConnection.getOutputStream());
writer.write("url");
writer.flush();
String response = Utils.streamToString(urlConnection
.getInputStream());
Log.i("", "*?*?*?*?*?*?*?*?*?*?*? response *?*?*?*?*?*?*?*?*?*?*?" + response);
JSONObject jsonObj = (JSONObject) new JSONTokener(response)
.nextValue();
tv.setText(jsonObj.toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}.start();
錯誤
java.io.FileNotFoundException: https://api.unsplash.com/photos?client_id=****
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:260)
W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
W/System.err: at com.ksucs.graduationproject.myinterests.MainActivity$1.run(MainActivity.java:97)
非常感謝() –