473,326 Members | 2,173 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,326 software developers and data experts.

Complete header control with curl

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 request inside it, but then curl adds a header after the custom_request portion.
Expand|Select|Wrap|Line Numbers
  1. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
^^^ the above produces a correct request, except it adds an additional set of headers after it.


I have tried sending the data in the CURLOPT_POSTFIELDS, along with setting header values in the CURLOPT_HTTPHEADER, but curl still sends the header values that it considers to be correct for a post request.

The following:
Expand|Select|Wrap|Line Numbers
  1. $header  = array("Content-type"=>"application/PTI26",
  2.   "Content-length"=>strlen($xml),
  3.   "Content-transfer-encoding"=>"text",
  4.   "Request-number"=>"1",
  5.   "Document-type"=>"Request",
  6.   "Interface-Version"=>"Test 1.4",
  7.   "Connection"=>"close");
  8.  
  9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  10.  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  11.  
produces this request:
Expand|Select|Wrap|Line Numbers
  1.  POST / HTTP/1.1
  2. Host: www.foobar.org
  3. Pragma: no-cache
  4. Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
  5. Content-Length: 993
  6. Content-Type: application/x-www-form-urlencoded
  7.  
Is there some way to get more control of the header?
or
Is there another option besides curl that can handle a custom ssl certificate?

Thanks
Andrew
Oct 4 '07 #1
4 7251
Atli
5,058 Expert 4TB
Hi Andrew. Welcome to The Scripts!

I haven't personally had much experience with cUrl so I'm afraid I can't help you much there. (I'm sure many of the other experts can, however)

But, you could always use sockets to send HTTP requests, giving you full control over the entire process. Check out the second example in that link.
Oct 4 '07 #2
Thanks for your reply,

I would like to use sockets, but I do not know if/how the following portion can be done:
Expand|Select|Wrap|Line Numbers
  1. curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM"); 
  2. curl_setopt($ch, CURLOPT_SSLCERT, $clientcertpath); 
  3. curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $clientcertpassword); 
  4.  
Never mind, now I see under the streams section that I can use fsockopen() and supply that certificate info. The second example here is somewhat close to what I need.

Thanks, wouldn't of found it wothout you.
Oct 4 '07 #3
Atli
5,058 Expert 4TB
I'm glad I could help :)

Don't hesitate to post again if you have any more questions or problems we can help with.
Oct 4 '07 #4
pbmods
5,821 Expert 4TB
Heya, Andrew.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]
Oct 4 '07 #5

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

Similar topics

1
by: Haluk Durmus | last post by:
Hello I checked out openssl,mm,apr,apr-util,apache 2,curl,libxml and php from cvs. php couse an ERROR I did the following steps:
3
by: Chris Fortune | last post by:
# uname -a Linux stargate.mxc-online.net 2.4.20-021stab022.2.777-smp #1 SMP Wed Jul 28 17:12:37 MSD 2004 i686 i686 i386 GNU/Linux I recompiled PHP with mcrypt, openssl, and curl phpinfo():...
3
by: Hans | last post by:
Hi everybody, I am desperately trying to log into my account at godaddy.com with PHP and Curl and just cannot make it happen. Has anybody written a script for this purpose? Here is what I...
0
by: Dean Hallman | last post by:
Hello, I am developing a BHO that should add a custom HTTP header on a specific domain only. Don't want the header globally, otherwise I could just add a registry key. So, on...
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......
2
by: sundar22in | last post by:
Hi, I want to access a part of file in PHP(Instead of whole file). I understood HTTP Range header is the solution. How do we implement HTTP Range header in PHP??? Iam using fopen() method to...
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...
0
by: jsherk | last post by:
I've spent HOURS searching the net for an answer to this, but can't find it... I trying to send data using the POST method and also have the control of the browser be turned over to the website...
1
by: jeddiki | last post by:
I am using curl and DOMDocument to extract the links from my website. This is my script: require("my_functions.php"); $target_url =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.