이 cURL 스크립트를 PHP 및 Guzzle과 함께 사용하도록 변환하려고합니다. 아래와 같이 쿠키를 설정할 수 있었지만 나중에 필요한 xml 파일을 보낼 수 없습니다.
cURL 스크립트
# First, we need to get the cookie
curl [-k] –dump-header <header_file> -F “action=login” -F “username=<username>” -F “password=<password>” https://<website_URL>
# Then, we can use that cookie to upload our orders
# XML Order Upload
curl -b <header_file> -F “import=@<order_file>” http://<website_URL>/importXMLOrder.php
이것이 내가 쿠키를 설정하는 것입니다. 다음 부분이 실제로 내가 가지고있는 xml 파일을 보내는 것이 무엇인지 잘 모르겠습니다.
$client = new \GuzzleHttp\Client();
$response = $client->post('http://website/login.php', array(
'body' => array(
'username' => 'xxxxx',
'password' => 'xxxxxx'
))
);
나는 또한 이것을 시도했다. 그러나 다음과 같은 오류 메시지가 나타납니다.
Call to undefined method GuzzleHttp\Message\Response::send()
$request = $client->post('http://website.com/import.php', array(
'body' => array(
'file_filed' => fopen('orders.xml', 'r')
)));
$response = $request->send();
$data = $response->xml();
print_r($data);
최신 정보
$request = $client->createRequest('POST','http://website.com/import.php', array(
'body' => array(
'file_filed' => file_get_contents('orders.xml', 'r')
)
));
$response = $client->send($request);
//var_dump($response); die;
$data = $response->xml();
echo '<pre>';
print_r($data);
send()
잘못된 수업에서 전화 를 거시 는 것 같습니다 . send()
의 방법입니다 \GuzzleHttp\Client
. 따라서 $client->send()
대신 해야 합니다.
그러나 $client->post()
요청을 생성하자마자 요청을 보냅니다. 당신이 사용하려는 경우 send()
당신은 교체해야합니다 post()
함께 createRequest()
: 여기 바와 같이, http://guzzle.readthedocs.org/en/latest/clients.html#creating-requests
fopen()
콘텐츠 대신 파일 핸들을 반환하는 호출에도 문제가 있습니다. file_get_contents()
대신 시도하십시오 .
편집하다:
인증 쿠키를 설정하려면 쿠키 항아리가 필요합니다. 다음을 시도하십시오.
$client = new \GuzzleHttp\Client();
$auth = $client->post('http://website/login.php', array(
'body' => array(
'username' => 'xxxxx',
'password' => 'xxxxxx'
),
'cookies' => true
));
동일한 사용 Client
:
$request = $client->createRequest('POST','http://website.com/import.php', array(
'body' => array(
'file_filed' => file_get_contents('orders.xml')
),
'cookies' => true
));
$response = $client->send($request);
//var_dump($response); die;
$data = $response->xml();
echo '<pre>';
print_r($data);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다