Jump to content

how to use PHP to POST to listening IP/port


tate_etc

Recommended Posts

i can post XML data to a website via cURL

 

can i use cURL to post XML to a local TCP IP/port?

 

when i simply switch the server from server website.com port 443 to server 127.0.0.1 port 2000, the script times out (port 80 works, of course)

 

all programs are installed on same PC. i have two programs that currently post XML data via java socket classes, so i know the ip/port is open

 

does anyone have any suggestions?

Link to comment
Share on other sites

  • 4 weeks later...

So I finally have gotten a connection between server/client via cURL. The problem was that I wasn't sending a string to the server. I mostly work with web-based programs & they usually error out differently, so I was surprised when I discovered that that was the problem...

 

Now, I would like to be able to send data to the server, but cURL appends header info to the string like this:

 

POST / HTTP/1.1

Host: ausrcsht02:2000

Accept: */*

Content-Length: 51

Content-Type: application/x-www-form-urlencoded

 

0,"004"1,"Assign Tracking Number"498,""499,"1"99,""

 

How do I post just the raw data? Here is my code:

 

<?

$ch = curl_init();

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, '0,"004"1,"Assign Tracking Number"498,""499,"1"99,""');

curl_setopt($ch, CURLOPT_TIMEOUT, 10);

curl_setopt($ch, CURLOPT_URL, "localhost:2000");

$contents = curl_exec($ch);

curl_close($ch);

echo $contents;

?>

 

Thanks in advance!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.