2016-02-17 26 views
0

好的,這就是我所擁有的,我可能完全錯誤,但我需要比我在網上找到的更多的方向。C#登錄到一個非交互式網站並通過URL傳遞XML

我想傳遞一個包含登錄信息的URL,然後在包含我的XML的同一個連接中傳遞另一個URL。就這樣,我似乎無法得到這個工作。請幫忙!!

這是我的代碼。

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Web; 
using System.Xml; 
using System.Net; 
using System.IO; 
using System.Configuration; 
using System.Data.SqlClient; 
using System.Data.Sql; 
using System.Data; 
using System.ComponentModel; 
using System.Collections.Specialized; 

namespace DataIntegration.DataSender 
{ 
class RaveDataSender 
{ 
    static void Main(string[] args) 
    { 

     System.Uri myUri = new System.Uri(@"https://api.myloginpage.com/edc_studyservices.jsp?action=importfile&filecontents=<?xml version='1.0'?><dataprocessitems><item>someitem</item></dataprocessitems>&filename=1.xml"); 
     System.Uri loginUri = new System.Uri(@"https://api.myloginpage.com/login.jsp?studyid=something&action=login&login=myLoginName&password=myPassword"); 
     byte[] mybytes = Encoding.ASCII.GetBytes("https://api.myloginpage.com/edc_studyservices.jsp?action=importfile&filecontents=<?xml version='1.0'?><dataprocessitems><item>someitem</item></dataprocessitems>&filename=1.xml"); 
     byte[] loginbytes = Encoding.ASCII.GetBytes(@"https://api.myloginpage.com/login.jsp?studyid=something&action=login&login=myLoginName&password=myPassword"); 
     CookieAwareWebClient client = new CookieAwareWebClient(); 

     client.UploadDataAsync(loginUri, loginbytes); 
     client.UploadDataAsync(myUri, mybytes); 

     client.Dispose(); 


    } 

    public class CookieAwareWebClient : WebClient 
    { 
     private CookieContainer cookie = new CookieContainer(); 

     protected override WebRequest GetWebRequest(Uri address) 
     { 
      WebRequest request = base.GetWebRequest(address); 
      if (request is HttpWebRequest) 
      { 
       (request as HttpWebRequest).CookieContainer = cookie; 
      } 
      return request; 
     } 
    } 


    } 
} 

編輯這是我最終做的。

using (var client = new CookieAwareWebClient()) 
     { 
      byte[] authresp = client.UploadData(loginUri, loginbytes); 
      byte[] dataRespose = client.UploadData(xmlUri, reqbytes); 

      string authResult = System.Text.Encoding.UTF8.GetString(authresp); 
      string result = System.Text.Encoding.UTF8.GetString(dataRespose); 
      client.Dispose(); 
     } 
+0

所以這邊的問題在這裏,你是否傳遞用戶名和密碼明文..?哇我不會這樣做..如果你有一個具有登錄頁面的網絡應用程序,一旦你驗證不處理那些類型的信息在URL中處理重定向 – MethodMan

+0

感謝您的注意。顯然這裏的價值並不真實。幸運的是,這是給出的規範,以及我如何被指示來處理這種整合。但是,是的,你在這裏傳遞給合唱團。 – John

+0

哇這不是一個好方法..也許他們沒有意識到這樣做可能會暴露自己... – MethodMan

回答

0

我認爲這個問題可能是你在異步方法仍在運行時處置對象。