teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

zzz

2020/11/07 09:18

投稿

katahaba
katahaba

スコア15

title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,7 @@
8
8
  [["Australian_mist",0.6419525146484375],["american_short_hair",0.14048415422439575],["Arabian_Mau",0.13482220470905304],["BritishShortHair",0.07669025659561157],["Scottish_Fold",0.0020108497701585293]]
9
9
 
10
10
  ```コマンドライン
11
- curl -u xxx:yyy -F "image=@./public/xxxx.jpeg" http://whatcat.ap.mextractr.net/api_query
11
+ curl -u xxx:yyy -F "image=@.zzz" http://whatcat.ap.mextractr.net/api_query
12
12
  xxx : 「この猫なに猫?」のユーザ名
13
13
  yyy : 「この猫なに猫?」のユーザパスワード
14
14
  zzz : 識別したい画像のファイル名

2

コード変更

2020/11/07 09:18

投稿

katahaba
katahaba

スコア15

title CHANGED
File without changes
body CHANGED
@@ -62,6 +62,15 @@
62
62
  上記のhttps://note.com/kawa1228/n/n55b3cfcb543cを参考にさらにやってみた
63
63
  ```php
64
64
 
65
+ $image_url='./public/download.jpeg';
66
+ $base = "http://whatcat.ap.mextractr.net/api_query";
67
+ // $param = "?username=env('whatcat_username')&passowrd=env('whatcat_password')&image=$image_url";
68
+ $param = "?username=env('whatcat_username')&passowrd=env('whatcat_password')&image='@'.$image_url";
69
+ $url = $base . $param;
70
+ $headers = [];
71
+ $method='GET';
72
+
73
+
65
74
  $curl = curl_init();
66
75
  curl_setopt($curl, CURLOPT_URL, $url);
67
76
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);

1

追加テスト

2020/11/06 23:08

投稿

katahaba
katahaba

スコア15

title CHANGED
File without changes
body CHANGED
@@ -57,4 +57,32 @@
57
57
  GuzzleHttp \ Exception \ ClientException (403)
58
58
  Client error: `POST http://whatcat.ap.mextractr.net/api_query` resulted in a `403 FORBIDDEN` response: {"detail":"認証情報が含まれていません。"}
59
59
 
60
- すごく初心者なのでそれをふまえて回答いただけると助かります。
60
+ すごく初心者なのでそれをふまえて回答いただけると助かります。
61
+
62
+ 上記のhttps://note.com/kawa1228/n/n55b3cfcb543cを参考にさらにやってみた
63
+ ```php
64
+
65
+ $curl = curl_init();
66
+ curl_setopt($curl, CURLOPT_URL, $url);
67
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
68
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
69
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
70
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
71
+
72
+
73
+ $responseJsonText = curl_exec($curl);
74
+ $body = json_decode($responseJsonText , true);
75
+
76
+ $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
77
+ curl_close($curl); // curlの処理終わり
78
+
79
+ $result = [];
80
+ $result['http_code'] = $httpCode;
81
+ $result['body'] = $body;
82
+
83
+ return $result;
84
+
85
+ dd($result);
86
+ ```
87
+ 結果表示
88
+ {"http_code":403,"body":{"detail":"\u8a8d\u8a3c\u60c5\u5831\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u305b\u3093\u3002"}}