|
 |
|
อยากจะเปลี่ยนจาก fsockopen ไปใช้ CURL แทนกันได้มั้ยครับ |
|
 |
|
|
 |
 |
|
สวัสดีครับผมอยากทราบว่าผมจะเปลี่ยนจาก fsockopen เป็น CURL แทนได้ไหมครับโดยที่ต้นฉบับโค๊ดใช้ fsockopen
ตามนี้ครับ
Code (PHP)
function postData3($file,$ktsub,$name,$password=NULL,$checksum,$checkkey,$pic=2,$body) {
$dat = '';
$dat .= "-----------------------------262762878619883\r\n";
$dat .= "Content-Disposition: form-data; name=\"file\"\r\n";
$dat .= "\r\n";
$dat .= $file."\r\n";
$dat .= "-----------------------------262762878619883\r\n";
$dat .= "Content-Disposition: form-data; name=\"ktsub\"\r\n";
$dat .= "\r\n";
$dat .= $ktsub."\r\n";
$dat .= "-----------------------------262762878619883\r\n";
$dat .= "Content-Disposition: form-data; name=\"name\"\r\n";
$dat .= "\r\n";
$dat .= $name."\r\n";
$dat .= "-----------------------------262762878619883\r\n";
$dat .= "Content-Disposition: form-data; name=\"password\"\r\n";
$dat .= "\r\n";
$dat .= $password."\r\n";
$dat .= "-----------------------------262762878619883\r\n";
$dat .= "Content-Disposition: form-data; name=\"checksum\"\r\n";
$dat .= "\r\n";
$dat .= $checksum."\r\n";
$dat .= "-----------------------------262762878619883\r\n";
$dat .= "Content-Disposition: form-data; name=\"checkkey\"\r\n";
$dat .= "\r\n";
$dat .= $checkkey."\r\n";
$dat .= "-----------------------------262762878619883\r\n";
$dat .= "Content-Disposition: form-data; name=\"pic\"\r\n";
$dat .= "\r\n";
$dat .= $pic."\r\n";
$dat .= "-----------------------------262762878619883\r\n";
$dat .= "Content-Disposition: form-data; name=\"body\"\r\n";
$dat .= "\r\n";
$dat .= $body."\r\n";
$dat .= "-----------------------------262762878619883\r\n";
$dat .= "Content-Disposition: form-data; name=\"file-to-upload-01\"; filename=\"PepsiCorp.gif\"\r\n";
$dat .= "Content-Type: image/jpeg\r\n\r\n";
$dat .= $att_data."\r\n";
$dat .= "-----------------------------262762878619883--\r\n";
$servers = array();
$servers[0] = array('bbs2.pramool.com','/cgi-bin/webboard/followup3.cgi');
$server = rand(0,count($servers)-1);
$connection = fsockopen($servers[$server][0], 80, $errorNumber, $errorString, 15);
$requestHeader = 'POST ' . $servers[$server][1] . " HTTP/1.1\r\nHost: " . $servers[$server][0] . "\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0\r\nReferrer: http://bbs2.pramool.com/webboard/followup.php3\r\nContent-Type: multipart/form-data; boundary=---------------------------262762878619883\r\nContent-Length: ".strlen($dat)."\r\n\r\n";
$requestHeader .= $dat;
fputs($connection, $requestHeader);
while (!feof($connection)) {
$data.=fgets($connection,120);
}
fclose($connection);
define('RESP_BEGIN','<center>');
define('RESP_END','</center>');
$tmp = strstr($data,RESP_BEGIN);
$resp = substr(strstr($tmp,RESP_BEGIN),strlen(RESP_BEGIN),strpos(strstr($tmp,RESP_BEGIN),RESP_END) - strlen(RESP_BEGIN));
return $resp;
Tag : PHP, CakePHP, Web Service

|
|
 |
 |
 |
 |
Date :
2014-09-01 20:09:19 |
By :
MrAoffeR |
View :
974 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ว่าแต่ตอนนี้ติดอะไร หรือเปล่าครับ 
|
 |
 |
 |
 |
Date :
2014-09-02 12:11:04 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2014-09-02 12:11:04
รายละเอียดของการตอบ ::
ตอนนี้ไม่ติดคับสามารถโพสได้ครับ แต่อยากจะเปลี่ยนให้เป็น curl ครับ
ไม่ทราบว่าจะมีทางไหมครับ ผมลองเขียนเองแต่พอส่งคำสั่ง POST ไปมันขึ้นเหมือนว่าผมไม่ได้กรอกข้อมูลครับอันนี้คือที่ผมลองครับ
Code (PHP)
function postData($file,$ktsub,$name,$password=NULL,$checksum,$checkkey,$pic=2,$body)
{
$URL = 'http://bbs2.pramool.com/cgi-bin/webboard/followup3.cgi';
$ref = 'http://bbs2.pramool.com/webboard/followup.php3';
$fields = array( 'file'=>$file, 'ktsub'=>$ktsub, 'name'=>$name, 'password'=>$password, 'checksum'=>$checksum, 'checkkey'=>$checkkey, 'pic'=>$pic, 'body'=>$body, 'file-to-upload-01'=>$att_data);
$postvars = '';
$att_data = 'PepsiCorp.gif';
foreach($fields as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
rtrim($postvars, '&');
$ch = curl_init();
$timeout = 10; // set to zero for no timeout
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt ($ch, CURLOPT_URL, $URL);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
define('RESP_BEGIN','<center>');
define('RESP_END','</center>');
$tmp = strstr($data,RESP_BEGIN);
$resp = substr(strstr($tmp,RESP_BEGIN),strlen(RESP_BEGIN),strpos(strstr($tmp,RESP_BEGIN),RESP_END) - strlen(RESP_BEGIN));
return $resp;
}
|
 |
 |
 |
 |
Date :
2014-09-02 19:01:14 |
By :
MrAoffeR |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สามารถทำได้มั้ยคับ
|
 |
 |
 |
 |
Date :
2014-09-04 14:13:04 |
By :
MrAoffeR |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|