Is the structure right to send xml-data or has it to be written in another way?
When i connect to the ip-address and the port the sending string must have the
right syntax.
Any idea?
Moderator: General Moderators
Code: Select all
<?php
function sendPost($host,$path,$data)
{
$method = 'POST';
$fp = fsockopen($host, 80);
fputs($fp, "$method $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp,"Content-type: application/x-www-form- urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($data) . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
while (!feof($fp)) {
$sent .= fgets($fp,128);
}
fclose($fp);
return $sent;
}
/*
usage:
$stringa = "<your_xml/>"
$sent = sendPost("thehost.com","/path/to/file.php", $stringa);
*/
?>I opened dos-window, write telnet, computer said not found, had to google and found a page how to install telnet in vista, installed, write o xx.xx.xx.xx xxxx and got error:Eric! wrote:I don't know easyterm. You must be using vista and got screwed by the lack of dos and telnet.
It sounds like that port is blocked to me. You should get something like
When it doesn't work you should get something like Connect failed.Code: Select all
c:>telnet http://www.example.com 80 <CR> Connecting to http://www.example.com.... [at this point the screen will go blank (wait for this to happen) and anything you type will not be echoed back] HEAD / HTTP/1.1<CR> Host: http://www.example.com<CR> <CR>
Talk to the admin running the host you are trying to connect to and tell them what you are trying to do. Perhaps they are using a different port or only accepting SSL connections on XX port or something.....Code: Select all
C:> telnet 60.92.12.56 80 <CR> Connecting To 60.92.12.56...Could not open connection to the host, on port 80: Connect failed.
Code: Select all
<?php
$fp2 = fsockopen("tcp://xx.xx.xx.xx", xxxx, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
$szData2 = 'xxxx;xxxx';
fwrite($fp2, $szData2);
$szData2 = ' ';
fwrite($fp2, $szData2);
// print $szData2;
// $buffer hamnar allt som mottagits ifrån servern
// $fp innehåller din fsockopen connection
while(true)
{
$str = fread($fp2, 1);
$buffer .= $str;
print $buffer;
if($str == "\n")
{
break;
}
}
// fwrite($fp, "\n");
// echo fread($fp, 26);
fclose($fp);
}
?>
Code: Select all
<?php
$handle = fsockopen("tcp://xx.xx.xx.xx", xxxx, $errno, $errstr);
$out = 'xxxx;xxxxx';
fwrite($handle, $out);
$out2 = ' ';
fwrite($handle, $out2);
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
echo $contents;
}
fclose($handle);
?>
I thought this forum was for php questions for beginners, but maybe i am wrong, just super professionals like you...astions wrote:I'm not sure why our members are helping you perform a job you clearly aren't qualified for, but if you post one more line of code without using code tags I'm going to lock this thread.
Code: Select all
tags when posting code in the forums
[*]We don't do homework assignments
[*]We don't do your paid assignments for you[/list]
I hope you understand.astions wrote:This forum is for PHP developers of all levels of experience. Regardless of your experience however, you must understand that we hold all members to the same standards. Namely:
- You must obey the forum rules
- You must use the appropriate
Code: Select all
tags when posting code in the forums [*]We don't do homework assignments [*]We don't do your paid assignments for you[/list] I hope you understand.[/quote] If you have been here in forum since 2002 you could give me an answer to my question why the code doesn't work or if i have to code it another way....
Code: Select all
$szData = '<?xml version="1.0" encoding="Windows-1252" ?>
<Signal xmlns="http://b.se/T.xsd">
<Version>1.0</Version>
<SignalType>Entry</SignalType>
<PositionType>Long</PositionType>
<Instrument>OM Sweden:SE0007286893:SEK</Instrument>
<Strategy>WAMPA</Strategy>
<Price>875</Price>
<Weight>1</Weight>
<Comment>WAMPA</Comment>
</Signal>';
Code: Select all
$szData = '<?xml version="1.0" encoding="Windows-1252" ?>
<Signal xmlns="http://b.se/T.xsd">
<Version>1.0</Version>
<SignalType>Entry</SignalType>
<PositionType>Long</PositionType>
<Instrument>OM Sweden:' & $isin & ':SEK</Instrument>
<Strategy>WAMPA</Strategy>
<Price>' & $pris & '</Price>
<Weight>1</Weight>
<Comment>WAMPA</Comment>
</Signal>';
]