doskmc7870 2019-05-13 17:23
浏览 121

在curl_setopt中在PUT或POST之间交替

So I am currently working on a bunch of curl statements in PHP with a sql table to modify or create new keys, based on the $flag. This will be of set size 2 without change (or atleast for now).

What I am wondering is if Flag1 exists in this url, I would want to use a PUT, but Flag2 does not exist, I would need a POST. How would I be able to modify this code to determine PUT vs POST.

The loop logic has not been implemented yet. For now I am just trying to put $flag[0] in with $new_Val[0] and trying to modify PUT vs POST but I dont know how.

$flag = array("Flag1", "Flag2");
$new_Val = array("Val1", "Val2");    
$url = "myurl/thing/$flag/id/1112";
$my_data = array( "Key" => "$flag[0]", "Value" => "$new_Val[0]");
$ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($my_data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array( stuff in here) 
    result = curl_exec($ch);
    $json = json_decode($result);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?