類比提交的問題

來源:互聯網
上載者:User
瀏覽器顯示的

參數為:
method GET
model {"searchString":"B0036SGFB6","lang":"ja_JP","marketPlace":"A1VC38T7YXB528"}

原始碼為:
method=GET&model=%7B%22searchString%22%3A%22B0036SGFB6%22%2C%22lang%22%3A%22ja_JP%22%2C%22marketPlace%22%3A%22A1VC38T7YXB528%22%7D


請問curl_setopt($ch, CURLOPT_POSTFIELDS, $data)中的$data應該怎麼寫呢?




回複討論(解決方案)

$data 是一個關聯陣列就可以了,關聯鍵就是表單控制項的 name

xuzuning大大:
我現在是這樣的

$data='method=GET&model='.urlencode('{"searchString":"B0036SGFB6","lang":"ja_JP","marketPlace":"A1VC38T7YXB528"}');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

得到了我想要到結果,但現在有個問題:
$data_ar=array(
"searchString"=>"B0036SGFB6",
"lang"=>"ja_JP",
"marketPlace"=>"A1VC38T7YXB528"
);

請問我怎麼把$data_ar提交出去呢??

我想提交數組出去,而不是一段死的字串

$data_ar=array(
"searchString"=>"B0036SGFB6",
"lang"=>"ja_JP",
"marketPlace"=>"A1VC38T7YXB528"
)請問我怎麼把$data_ar提交出去呢??;

得到的結果,我用print_r($value)的內容:
{"data":[{"link":"http://www.amazon.co.jp/gp/product/B0036SGFB6/ref=xx_xx_cont_xx/378-0276217-1847765","dimUnits":"センチメ?トル","thumbnail":"https://images-na.ssl-images-amazon.com/images/I/41zK5Evzv2L._SL80_.jpg","subCategory":"14700954","dimensions":{"width":7.3914,"length":20.8026,"height":2.794},"gl":"gl_pc","image":"https://images-na.ssl-images-amazon.com/images/I/41zK5Evzv2L._SL120_.jpg","weightUnits":"キログラム","productGroup":"147","weight":"0.0998","asin":"B0036SGFB6","whiteGlovesRequired":"N","title":"ELECOM USB2.0ケ?ブル A-Bタイプ 2m ブラック U2C-B20BK [Personal Computers]"}],"errorMessage":null}

這不是一個數組嗎?為什麼$value[0]或$value["data"]沒有內容輸出??

你 print_r($value) 得到的是 json 串
需要用 json_decode 解碼後才可使用

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.