Witam, posiadam prostą metodę Post przyjmującą 2 argumenty, która ma łączyć się z wybraną stroną, wysyłać do niej dane poprzez $_POST i zwracać wynik. Problem w tym, że wynik nie może być zwrócony w postaci stringu.. Przeszukałem pół internetu aby znaleźć pomoc, ale nic nie mogę znaleźć, może ktoś mi pomoże? :)
Kod wygląda tak, zawsze wynik próbuję wyrzucić do MessageBoxu, żeby sprawdzić, czy jest on stringiem, ale ciągle wyrzuca mi poniższy błąd:
Cannot implicitly convert type 'System.Windows.Forms.DialogResult' to 'string'
Jeśli chodzi o sam kod:
public string Post(string url, string data)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
byte[] bdata = Encode.GetBytes(data);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ServicePoint.Expect100Continue = false;
httpWebRequest.ContentLength = bdata.Length;
httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Method = "POST";
httpWebRequest.UserAgent = UserAgent;
Stream reqStream = reqStream = httpWebRequest.GetRequestStream();
reqStream.Write(bdata, 0, bdata.Length);
reqStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
string responseString = String.Empty;
using (Stream stream = httpWebResponse.GetResponseStream())
{
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
responseString = reader.ReadToEnd();
}
return MessageBox.Show(responseString);
}
Błagam o pomoc.