如何与一个固定的URL地址建立连接

heraldliz 2003-11-20 12:14:02
我想往一个固定的URL地址传递一个XML数据包,首先是不是需要建立与这个地址的一个连接,然后再发送?但是现在不知道如何用PHP语言与某个固定的URL地址建立连接,请教用什么方法,最好给出实例,多谢
...全文
104 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinyaoxp 2003-11-22
  • 打赏
  • 举报
回复
不错,收
heraldliz 2003-11-21
  • 打赏
  • 举报
回复
找到答案了
$ch = curl_init('http://localhost/important/parse.php');

$data = "<?xml version = \"1.0\"?>
<misc_command version=\"1.5\">
<command_name>provision</command_name>
<command_data_block>
<result_id>1234567</result_id>
<result_string>good</result_string>
</command_data_block>
</misc_command>";

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec ($ch);
curl_close ($ch);

就OK了
stan23 2003-11-20
  • 打赏
  • 举报
回复
不清楚你想做什么……
faucet 2003-11-20
  • 打赏
  • 举报
回复
使用socket
heraldliz 2003-11-20
  • 打赏
  • 举报
回复
比如在JAVA中如果想往某一个IP地址发送一个XML文件,首先需要建立一个连接。例如:

public boolean setupLink(String url){
boolean success = false;
String log = "";
try{
URL gateway = new URL(url);
connection = gateway.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
success = true;
log = "Connect to " + url + " succeed.";
} catch (IOException exception){
success = false;
log = "Connect to " + url + " failed: " + exception.getMessage();
}finally{
}
return success;
}

然后:
if(misclinker.setupLink(某个IP地址)) conn = misclinker.getConnection();
String req = "<?xml version=\"1.0\"?><misc_command version=\"1.5\">";
req += "<command_name>sso</command_name><command_data_block><sid>" + receivedSID + "</sid><service_id>" + serviceID + "</service_id>";
req += "<sp_id>" + sp_id + "</sp_id><sp_password>" + sp_password + "</sp_password></command_data_block></misc_command>";


misclinker.sendRequest(req);

这样就通过建立连接的misclinker把req发送到了某个IP地址。
我具体就是想知道在PHP中如何实现这些功能。包括如果与某个IP建立连接,然后通过这个连接往那个IP发送XML数据

这次能描述的清楚些了么?
stan23 2003-11-20
  • 打赏
  • 举报
回复
还是不理解……
heraldliz 2003-11-20
  • 打赏
  • 举报
回复
就是想对一个固定的URL地址发送一个XML文件

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧