2016-11-07 9 views
0

イムを動作しないし、WebRequestクラス これはUTF-8文字のURLは、LANケーブルを介して、MACHINにいくつかのデータを送信しようと

public class MyWebRequest 
{ 
    private WebRequest request; 
    private Stream dataStream; 

    private string status; 

    public String Status 
    { 
     get 
     { 
      return status; 
     } 
     set 
     { 
      status = value; 
     } 
    } 

    public MyWebRequest(string url) 
    { 

     request = WebRequest.Create(url); 
    } 

    public MyWebRequest(string url, string method) 
     : this(url) 
    { 

     if (method.Equals("GET") || method.Equals("POST")) 
     { 
      request.Method = method; 
     } 
     else 
     { 
      throw new Exception("Invalid Method Type"); 
     } 
    } 

    public MyWebRequest(string url, string method, string data) 
     : this(url, method) 
    { 

     string postData = data; 
     byte[] byteArray = Encoding.UTF8.GetBytes(postData); 

     request.ContentType = "application/x-www-form-urlencoded"; 

     // Set the ContentLength property of the WebRequest. 
     request.ContentLength = byteArray.Length; 

     dataStream = request.GetRequestStream(); 

     dataStream.Write(byteArray, 0, byteArray.Length); 

     dataStream.Close(); 

    } 

    public string GetResponse() 
    { 
     WebResponse response = request.GetResponse(); 

     this.Status = ((HttpWebResponse)response).StatusDescription; 

     dataStream = response.GetResponseStream(); 

     StreamReader reader = new StreamReader(dataStream); 

     string responseFromServer = reader.ReadToEnd(); 

     reader.Close(); 
     dataStream.Close(); 
     response.Close(); 

     return responseFromServer; 
    } 

} 

を使用してクラスイムで、アクションコードが

です
command="?insert_employee:cart_number=0007989222&name=علي&last_name=رمضاني&finger_number=123&?"; 
MyWebRequest wr = new MyWebRequest(command, "GET"); 
string Response = wr.GetResponse(); 

あなたはそこにいくつかのUTF-8文字が私の命令であり、それは両方のブラウザでは動作しませ用量および私はこの文字列をしようとすると、私のアプリケーション が、それは完璧に動作ご覧のとおり

command = "?insert_employee:cart_number=0007989222&name=ali&last_name=ramazani&finger_number=123&?" 

私は "urlの代わりにuriを使用する"、 "httpUtility.UrlEncodeを使用する"などのstackoverflowで見つかった多くの方法をテストしましたが、どれも有効ではなかったか、間違った方法で使用していました。

あなたは何か助けてもらえますか?

答えて

0

デコードを実行するプラットフォームやブラウザに関係なく、一貫性のあるデコードされたURLを保証するために、URLのパス部分をエンコードする方法を使用できます。

Encoding

urlPrueba = "http://someexample.com/?insert_employee:cart_number=0007989222&name=علي&last_name=رمضاني&finger_number=123&?"; 
var uri = new Uri(urlPrueba); 
Console.WriteLine("urlPrueba" + " = " + uri.AbsoluteUri); 
+0

の美しい説明があるのに対し、私はすでにあまりにもこれを試してみましたが、ない成功! –

+0

uriも私を助けませんでした –

関連する問題