I want to build a little remote tool for a school project. (XBMC)
At first I would say, that a string variable doesn´t include quotes, but \", which should picture quotes in a textbox and somewhere else. Firstly i mean C# makes quotes with that trick in a Webrequest too, but he doesn´t. Furthermore i can reach my device, but the ResponseReader doesn´t give any answer, but this isn´t important, because i can delete this part in need.
Here is an example for the variable Übergabe
:
{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"Input.Up\"}
textBox2.Text includes the password and textBox1.Text includes the server.
How should i solve this?
I'm trying to make this WebRequest (method) work:
private void Xorg (string Übergabe)
{
try
{
WebRequest MyRequest;
MyRequest = WebRequest.Create(("http://root:") + (textBox2.Text) + ("@") + (textBox1.Text) + ("/jsonrpc?request=") + (Übergabe));
MyRequest.Method = "GET";
textBox3.Text = ("http://root:*****") + ("@") + (textBox1.Text) + ("/jsonrpc?request=") + (Übergabe);
Stream ResponseStream;
ResponseStream = MyRequest.GetResponse().GetResponseStream();
StreamReader ResponseReader = new StreamReader(ResponseStream);
while (ResponseReader.ReadLine() != null)
{
listBox2.Items.Add(ResponseReader.ReadLine());
}
}
catch
{ listBox2.Items.Add("Server antwortet nicht! / Fehlerhafte Eingabe!"); }
}
Use WebUtility.UrlEncode :
WebRequest MyRequest = WebRequest.Create(("http://root:") + (textBox2.Text) + ("@") + (textBox1.Text) + ("/jsonrpc?request=") + WebUtility.UrlEncode(Übergabe));
"
must be converted to %22
. With UrlEncode you ensure that all character are properly converted