需要帮助2将curl转换为php


Need Help 2 Convert curl to php

需要将linux curl命令转换为php代码

curl -H "Host: domain.com" -H "User-Agent: Apache-HttpClient/android/S5830i" -H "Expect: 100-continue" -H "Cookie: JSESSIONID=0000czjOPByVBxvGmsdvsdsdAADSdjka56f" -H 
     "Cookie2: $Version=1" --data "plat=andro&
      secretKey=628448d5213123b89196f108de&platformver=6.0.GA_v20150301812_r23&konyreportingparams=
      {"plat":"android","aid":"ISmart","aver":"1.0.0","aname":"ecure","did":"3544621","os":"2.3.6","stype":"b2c","dm":"GT-S5530i",
      "ua":"GT-S5830i","chnl":"mobile","fid":"frmLandingPage","atype":"native",
      "kuid":"","rsid":"1450648518372-872f-70dc-c512","metrics":
      []}&serviceID=FetchOnline&cacheid=&channel=rc&appver=1.0.0&
     appID=ISmartOTP&httpconfigs= { timeout : 50.0,  } "
     --compressed https://211.211.19.39/middleware/MWServlet

您可以尝试以下方式:

$fields = 2; // no of fields that can be change as per your params
$fields_as_string = "key=value&key2=value"   // insert your param here 
$url = "yoururl.com"; // your url
//open the curl connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
// set the number of post fields
curl_setopt($ch,CURLOPT_POST, $fields);
// set the fields
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_as_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);