我有一個簡單的表格,我想轉換成PHP後端系統。CURL不發佈數據到URL
現在這個表單有一個提交到URL的動作 - 只有當名稱爲postdata
且正確信息的數據被提交(xml已被編碼)時,該URL才接受邀請。
作品: - 請注意,輸入名字叫做postdata
和值包含xml
這一直urlencoded
和它完美的作品。
<form name="nonjava" method="post" action="https://url.com">
<input name="postdata" id="nonjavapostdata" type="hidden" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;" />
<button type="submit" name="submit">Button</button>
</form>
不過,我想通過PHP中的postdata
元件移動的很多信息都是通過這種方式傳遞到實現以下。
請注意:鏈接是https,但它不是在本地工作,所以我不得不在CURL內禁用它。
<?php
$url = 'https://super.com';
$xmlData = '<?xml version="1.0" encoding="utf-8"?>
<postdata
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<api>2</api>
</postdata>';
$testing = urlencode($xmlData);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postdata=" . $testing);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$response = curl_exec($ch);
// Then, after your curl_exec call:
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
echo $header_size . '<br>';
echo htmlspecialchars($header) . '<br>';
echo htmlspecialchars($body) . '<br><br>';
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "$http_status for $url <br>";
?>
我不斷收到302錯誤(這是URL內容沒有找到數據,以便其重定向到找不到網頁。)
我想你正在尋找CURLOPT_FOLLOWLOCATION curl標誌 – Smokie