Post File with curl

22 views
Skip to first unread message

gmoeller54

unread,
Feb 6, 2014, 11:22:32 PM2/6/14
to nzp...@googlegroups.com
Greetings,
Kind of stumped - need to post an xml for a remote printer server.
What would be preventing me from posting the xml with the following code?
I've been having a person at the remote server checking logs - nothing hitting the server yet!


$file2  = "xxxxx/$xxxxxFile.xml";
 
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_INFILESIZE, filesize($file2));
 
$fp = fopen($file2, "r");
curl_setopt($c, CURLOPT_INFILE, $fp);
 
curl_exec($c);
 
curl_close($c);
fclose($fp);

Thanks!

Nick

unread,
Feb 7, 2014, 4:32:15 AM2/7/14
to nzp...@googlegroups.com
You have .com in the url - is the printer internet facing or behind a router or firewall?
What at the response headers you get back from the curl request?
Can you access the URL in your browser, does that log a request if you do that.

Nick

gmoeller54 .

unread,
Feb 7, 2014, 9:00:38 AM2/7/14
to nzp...@googlegroups.com
Thanks for the response!
The printer is behind a firewall that is 'wide open' - I assume there is a router as well - I will ask.
I don't get any response headers back from the request (at least I think).
If you type the URL directly into the browser, the screen goes blank 
- the printer said that is what is supposed to happen, but they do not receive any log of my attempt actually touching the server.
If you use Firefox HTTP Resource Test Add-on, I do get a header response.


--
--
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to nzp...@googlegroups.com
To unsubscribe, send email to
nzphpug+u...@googlegroups.com
---
You received this message because you are subscribed to a topic in the Google Groups "NZ PHP Users Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nzphpug/F21rdaGpRO8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nzphpug+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Garrett Moeller
GIS/Web/Urban Planning
garrettmoeller.com


gmoeller54 .

unread,
Feb 7, 2014, 10:11:50 AM2/7/14
to nzp...@googlegroups.com
Tested again this morning - HTTP Resource Test works fine from both a random network and from within the server I am running my website from.
The printer sees that it hits their server in their logs as well.  This is by using the XML that the mail.php is supposed to send and by sending it directly to the .dll URL that I have in the mail.php.
Sending it from the mail.php is not working.  I don't understand - it looks like my syntax is correct in my mail.php, using cURL - but it is not working :-/

Shahzeb Farooq Chohan

unread,
Feb 7, 2014, 12:08:14 PM2/7/14
to nzp...@googlegroups.com
Hello gmoeller54,
Please have a look at this thread I have written a blog post about the same in past post an XML file using PHP to remote server without ftp
Please let me know you still face the same problem.

Thanks
Shahzeb
eCaroBar.com

gmoeller54

unread,
Feb 7, 2014, 12:31:55 PM2/7/14
to nzp...@googlegroups.com
Thanks for your response Shahzeb!
Here is what I have done.
Please keep in mind that there is a .dll file on the printer server that needs to be accessed.
The xml is POSTed to this .dll

<?php


 $ch = curl_init('xxx.com/xxx.dll');
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
 curl_setopt($ch, CURLOPT_POSTFIELDS, $thistext);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'Content-Type: application/xml',
  'Content-Length: ' . strlen($thistext))   );                                                                                                                  
  $result = curl_exec($ch);
 print_r($result);
 curl_close($ch);
 
?>

As you can see I modified your code to something slightly different.
I need to POST the xml to this .dll - I do not seem to be having any luck!

If I simply ping the .dll address from the server, it is successful - so I do not think it is network or firewall related.
Just my syntax

gmoeller54

unread,
Feb 7, 2014, 12:51:52 PM2/7/14
to nzp...@googlegroups.com
FYI I am using php 5.2.17 on windows server (iis)

David Neilsen

unread,
Feb 7, 2014, 1:30:57 PM2/7/14
to nzp...@googlegroups.com
Does it work from the CLI? If not, enable verbose output and have a look at that.



On Sat, Feb 8, 2014 at 6:51 AM, gmoeller54 <gmoe...@gmail.com> wrote:
FYI I am using php 5.2.17 on windows server (iis)

--
--
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to nzp...@googlegroups.com
To unsubscribe, send email to
nzphpug+u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "NZ PHP Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nzphpug+u...@googlegroups.com.

gmoeller54 .

unread,
Feb 7, 2014, 2:48:26 PM2/7/14
to nzp...@googlegroups.com
Thanks David,
I am having a little trouble with the syntax for this test.  I have created a batch file and the error I am getting in command prompt is as follows: -d: requires parameter

It also doesn't like "<?xml version="1.0" encoding="utf-8"?>
I can provide the full batch file if you think appropriate (minus sensitive urls of course)

Further I am not really sure this is the issue.  I am able to run Firefox HTTP Resource Test, put in the remote server location of the .dll file, enter my xml data, select POST request, and get a successful header return.

This is why I am thinking it is the syntax for my mail.php


You received this message because you are subscribed to a topic in the Google Groups "NZ PHP Users Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nzphpug/F21rdaGpRO8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nzphpug+u...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages