php curl multipart / form-data proxy-authorization(basic)

我有一个问题:我试图发送 Headers ,但没有任何反应 .

这是“Live HTTPHeaders” Headers 的一部分(我替换了url):

http://some_site/news/

POST /news/ HTTP/1.1
Host: some_site
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://some_site/news/
Proxy-Authorization: Basic MTQ4YjU5YWMtM2VlOS00ZmIzLThlODItOTU0MjcxODhhZTRlOjAyNDdkNWRkNGY1MTE2NWUzODFlNDVhYTY1YzQ5OWYwMTRhYzA2ZTg=
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=---------------------------123064818248741452271123522
Content-Length: 893
-----------------------------123064818248741452271123522
Content-Disposition: form-data; name="BJpKD8Fx"

Hello!!!
-----------------------------123064818248741452271123522
Content-Disposition: form-data; name="file"; filename=""
Content-Type: application/octet-stream


-----------------------------123064818248741452271123522
Content-Disposition: form-data; name="parent"

155143
-----------------------------123064818248741452271123522
Content-Disposition: form-data; name="redirect"

0
-----------------------------123064818248741452271123522
Content-Disposition: form-data; name="eggs2"

UzFWa05qVnpjRmw4UWtwd1MwUTRSbmc9
-----------------------------123064818248741452271123522
Content-Disposition: form-data; name="submit"

Äîáàâèòü
-----------------------------123064818248741452271123522--

HTTP/1.1 302 Found

这是我的代码:

<?php

 $parent = 155129;

 function doPost( $url = 'http://some_site/news', $postdata = '' ){

 $resource = curl_init();
 curl_setopt($resource, CURLOPT_URL, $url);
 curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt ($resource, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt ($resource, CURLOPT_SSL_VERIFYHOST, 0);
 curl_setopt ($resource, CURLOPT_HTTPHEADER, array('Expect:'));
 curl_setopt ($resource, CURLOPT_HEADER, 1);
 curl_setopt ($resource, CURLOPT_COOKIEJAR, 'cookie.txt');
 curl_setopt($resource,CURLOPT_COOKIEFILE,'cookie.txt');
 curl_setopt($resource, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
 if( $postdata != '' ) {
     curl_setopt($resource, CURLOPT_POST, true);
     curl_setopt($resource, CURLOPT_POSTFIELDS, $postdata);
 }
 curl_setopt($resource, CURLOPT_FOLLOWLOCATION, true);
 $result = curl_exec($resource);
 curl_close($resource);
 return $result;

}

$c = doPost();
preg_match('#id="textarea_form_'.$parent.'" name="(.*?)"#ims', $c, $textName);
preg_match('#<form.*?\/form>#ims', $c, $arr );
preg_match('#name=eggs2.*?value="(.*?)">#ims', $arr[0], $egss2);

$postdata = array(
    $textName[1]=> 'Hello',
   'file'=>'@/;type=application/octet-stream',
   'parent' => $parent,
   'redirect'=> '0',
   'eggs2' => $egss2[1],
   'submit' => iconv('utf-8', 'cp1252', 'Добавить')
);

print_r(doPost('http://some_site/news',$postdata));
print_r( $postdata );

我做错了什么?

谢谢!

附: Hehehehehehehehehehehehehehehehehehehehehehe !!!!我解决了!谢谢大家的收看!祝好运

回答(1)

2 years ago

您需要像这样注入 Headers :

curl_setopt($resource, CURLOPT_HTTPHEADER, array(
'X-Apple-Tz: 0',
'X-Apple-Store-Front: 143444,12'
));