使用XML参数执行GET请求(PHP cURL)

I'm trying to implement this API method and sending a GET request using PHP cURL.

Here is my code:

    $url = 'https://crm.zoho.com/crm/private/xml/'.$module.'/'.$method.'?authtoken='.config('app.ZOHO_KEY').'&scope=crmapi&newFormat=1&id='.$record_id.'&xmlData='.$XML_data;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_exec($ch);

The URL computes to this:

https://crm.zoho.com/crm/private/xml/Contacts/updateRecords?authtoken=XXXX&scope=crmapi&newFormat=1&id=2410575000000139003&xmlData= <Contacts> <row no="1"> <FL val="Email Opt Out">true</FL> </row> </Contacts>

However, the request fails. I have tried str_replace(' ', '%20', $url) but this does not resolve the issue.

php
dongmiao260399
dongmiao260399 数据在正文中发送,而不是在网址中发送
3 年多之前 回复

1个回答




我试过str_replace('','%20',$ url)</ p>
< / blockquote>

你做错了。 适合该任务的工具是 urlencode() </ p>
\ n

编辑</ strong> </ p>

您应该重构代码并通过常规POST请求发送此数据,这正是它的用途。</ p> \ n </ div>

展开原文

原文

I have tried str_replace(' ', '%20', $url)

You do this wrong. Proper tool for the task is urlencode()

EDIT

You should refactor your code and sent this data via regular POST request, which is exactly what is it for.

duagfgfn1981
duagfgfn1981 为什么你通过GET而不是POST发送这个?
3 年多之前 回复
dongzhan1948
dongzhan1948 问题是由换行引起的,而且urlencode()也不起作用,因为我有/在我的XML结构中,我需要保留它们。
3 年多之前 回复
douzuo0711
douzuo0711 我也试过使用$ ch = curl_init(urlencode($ url)),但它仍然不起作用。
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐