473,388 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

POST with curl

384 256MB
I'm wondering if anyone can tell me where I'm going wrong here trying to post with curl?

Expand|Select|Wrap|Line Numbers
  1. $url = 'https://mysite.com/submit';
  2. $prefix = '-----';
  3. $boundary = rand(1000000000,9999999999);
  4. $fields_string = '';
  5.  
  6. $fields = array(
  7.     'chan'=>urlencode($_POST['chan']),
  8.     'redirect'=>urlencode($_POST['redirect']),
  9.     'file1'=>@$_FILES['file1'],
  10.     'file2'=>@$_FILES['file2']
  11. );
  12.  
  13. $contentType = "multipart/form-data; boundary=".$boundary;
  14. foreach($fields as $key=>$value) {
  15.     $fields_string .= $prefix.$boundary.'\r\n
  16.     Content-Disposition: form-data; name="'.$key.'"\r\n\r\n
  17.     '.$value.'\r\n';
  18. }
  19. $fields_string .= '\r\n'.$prefix.$boundary.'--';
  20.  
  21. print $fields_string."<br/>";
  22. $ch = curl_init();
  23. curl_setopt($ch, CURLOPT_POST,1);
  24. curl_setopt($ch, CURLOPT_ENCODING, $contentType);
  25. curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
  26. curl_setopt($ch, CURLOPT_URL,$url);
  27. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  28. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  29. if(!curl_exec($ch))    {
  30.     trigger_error(curl_error($ch));
  31. curl_close($ch);
Apr 12 '11 #1
1 2251
JKing
1,206 Expert 1GB
Can you give some more info? What's happening? What is supposed to be happening? Are there errors? etc...
Apr 12 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Angie | last post by:
Hello everybody, I have an osCommerce shopping cart on my site, which is an open-source product that uses php. I'm very new to php. I also have an online scheduling application that I outsourced...
0
by: rgparkins | last post by:
HI I have 2 problems, 1 of which is tied to PHP and 1 loosely tied, so I'll put this out there. Got a problem that I have been working on for a while now which involves implementing the...
6
by: Wescotte | last post by:
I'm writing a tiny php app that will log into our bank of america account and retrieve a file containing a list of checks that cleared the previous day. The problem I'm running into is when I...
0
by: nfhm2k | last post by:
I've been trying to find a solution to this for quite some time now... I even took a look at existing scripts... Including this one......
0
by: Raj | last post by:
Hi, I am newbie to programming with libcurl. the problem is i want to send my gmail username and password outside the browser and get access to my mail. this i am doing with LibCurl. Though i dont...
0
by: Raj | last post by:
Hi, I am newbie to programming with libcurl. the problem is i want to send my gmail username and password outside the browser and get access to my mail. this i am doing with LibCurl. Though i dont...
1
by: devranger | last post by:
Hello, I am in the process of learning PHP CURL and in doing some test examples I am having some issues with CURL that I do not fully understand. I am doing a test to use CURL to post and return...
4
by: zorro | last post by:
Hello there, I can't figure out why is it that when i use an array for my postfields it doesn't work : this works curl_setopt($curl, CURLOPT_POSTFIELDS, "clown=bozo" ); this doesn't...
4
by: herbivore | last post by:
I am using curl to do a post request to a server. The request contains xml data, the standard post headers sent by curl do not work. I have tried using the custom_request option with the whole post...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.