日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

[NetWork][C#.NET] 上傳 EPCIS Xml文件 到 ezTR

系統 2246 0

上篇已經提到如何利用序列化產生Xml文件( [XML][C#.NET] 處理 ezTRACK 的 EPCIS Xml文件 ),這篇是說明如何將Xml文件上傳到ezTRACK

先建立起方法模組:

    
      public
    
    
      bool
    
     Upload(
    
      string
    
     FileName)

{

    
    
      if
    
     (
    
      string
    
    .IsNullOrEmpty(FileName))

        
    
      throw
    
    
      new
    
     ArgumentNullException(
    
      "FileName"
    
    );

    
    
      if
    
     (!File.Exists(FileName))

        
    
      throw
    
    
      new
    
     FileNotFoundException(
    
      "FileName"
    
    );



    
    
      string
    
     fileName = FileName;

    
    
      string
    
     serverUrl = 
    
      "ezTRACK網址"
    
    ;

    
    
      string
    
     account = 
    
      "帳號"
    
    ;

    
    
      string
    
     password = 
    
      "密碼"
    
    ;



    Stream requestStream = 
    
      null
    
    ;

    FileStream fileStream = 
    
      null
    
    ;



    HttpWebRequest uploadRequest = 
    
      null
    
    ;

    HttpWebResponse uploadResponse = 
    
      null
    
    ;

    
    
      //忽略驗証
    
    

    ServicePointManager.ServerCertificateValidationCallback = 
    
      delegate
    
     { 
    
      return
    
    
      true
    
    ; };

    
    
      try
    
    

    {

        
    
      //DOTO:1.Create WebRequest
    
    
      //DOTO:2.Creat Request Stream
    
    
      //DOTO:3. Write Request Stream
    
    

    }

    
    
      catch
    
    

    {

        
    
      throw
    
    ;

    }

    
    
      finally
    
    

    {

        
    
      if
    
     (uploadResponse != 
    
      null
    
    )

            uploadResponse.Close();



        
    
      if
    
     (fileStream != 
    
      null
    
    )

            fileStream.Close();



        
    
      if
    
     (requestStream != 
    
      null
    
    )

            requestStream.Close();

    }

}
  

DOTO:1.所要做的是建立WebRequest

    uploadRequest = WebRequest.Create(serverUrl) 
    
      as
    
     HttpWebRequest;

uploadRequest.Method = 
    
      "POST"
    
    ;


    
      //uploadRequest.Method = WebRequestMethods.Http.Post;
    
    

uploadRequest.ContentType = 
    
      "application/soap+xml; charset=utf-8"
    
    ;

uploadRequest.Credentials = 
    
      new
    
     NetworkCredential(account, password);
  

DOTO:2.所要做的是建立RequestStream,把硬碟裡的檔案讀進來

    requestStream = uploadRequest.GetRequestStream();

fileStream = File.Open(fileName, FileMode.Open);




    
      byte
    
    [] buffer = 
    
      new
    
    
      byte
    
    [1024];


    
      int
    
     bytesRead;


    
      while
    
     (
    
      true
    
    )

{

    bytesRead = fileStream.Read(buffer, 0, buffer.Length);

    
    
      if
    
     (bytesRead == 0)

        
    
      break
    
    ;

    requestStream.Write(buffer, 0, bytesRead);

}
  

DOTO:3. 當 Request Stream 關閉後就寫入到 Server,利用HttpStatusCode判斷是否上傳成功

    requestStream.Close();



uploadResponse = uploadRequest.GetResponse() 
    
      as
    
     HttpWebResponse;


    
      if
    
     (uploadResponse.StatusCode == HttpStatusCode.OK)

    
    
      return
    
    
      true
    
    ;


    
      else
    
    
      return
    
    
      false
    
    ;
  

[NetWork][C#.NET] 上傳 EPCIS Xml文件 到 ezTRACK 的 Server


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 崇明县| 个旧市| 白朗县| 固阳县| 化隆| 邵武市| 平邑县| 永修县| 娄烦县| 永济市| 罗平县| 衡东县| 黄大仙区| 大理市| 宿迁市| 拉萨市| 囊谦县| 阜宁县| 蓬安县| 中阳县| 宁津县| 慈利县| 清水县| 天台县| 慈溪市| 辽中县| 涞水县| 瓦房店市| 河津市| 洱源县| 蓝山县| 崇仁县| 仪征市| 杭锦旗| 大方县| 海宁市| 千阳县| 太谷县| 平顶山市| 黄山市| 贵南县|