就是想对一个固定的URL地址发送一个XML文件

解决方案 »

  1.   

    比如在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数据这次能描述的清楚些了么?
      

  2.   

    找到答案了
    $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了