Laden...

HttpRequestResponse Timeout Problem

Erstellt von stan vor 18 Jahren Letzter Beitrag vor 17 Jahren 2.157 Views
S
stan Themenstarter:in
44 Beiträge seit 2005
vor 18 Jahren
HttpRequestResponse Timeout Problem

hallo,
ich habe ein beim problem beim senden, bzw empfangen eines http requestes!
zuerst sende ich einen request um die session id zu bekommen, dann einen login request, und noch einen anderen request, beginne ich dann wieder von vorne also beim request für session id bekomme ich beim login request keinen respone vom server...sondern nur ein timeout....hmmmm
vielleicht hat jemand eine idee!?
lg


request für session id:
-----------------------
HttpWebRequest get_request = (HttpWebRequest)WebRequest.Create("https://www.myzone.at/webkeeper/Controller");
get_request.CookieContainer = new CookieContainer();
      
HttpWebResponse get_response = (HttpWebResponse) get_request.GetResponse();
get_response.Cookies = get_request.CookieContainer.GetCookies(get_request.RequestUri);

String sessionid = "Cookie: ";
sessionid += get_response.Cookies[0].ToString();

login request:
--------------
HttpRequestResponse login_request = new HttpRequestResponse("https://www.myzone.at/webkeeper/Controller", "POST", "action=login&login=Anmelden&brand=myzone&username=xxxxxx&password=xxxxxxb&x=83&y=13");
login_request.SESSION_ID = sessionid;
login_request.SendRequest();



hier man meine sendrequest methode:
-----------------------------------------
public string SendRequest()
{
	string responseFromServer="";

	try
	{
		if((RequestMethod.ToUpper() != "GET") && (RequestMethod.ToUpper() != "POST"))
			throw new WebException(RequestMethod+ " is not a valid method.  Use GET or POST.");

		// Create a request using a URL that can receive a post. 
		HttpWebRequest request = (HttpWebRequest) WebRequest.Create(URL);
		// Set the Method property of the request to POST.
				request.Method = RequestMethod;
		// Set the sessionid to the Header
		request.Headers.Add(SessionId);

		// check if asked to do a POST request, if so then modify 
		// the original request as it defaults to a GET method
		if(RequestMethod.ToUpper()=="POST") 
		{
			// Create POST data and convert it to a byte array.
			byte[] byteArray = Encoding.UTF8.GetBytes (PostData);
					
			// Set the ContentType property of the WebRequest.
			request.ContentType = "application/x-www-form-urlencoded";
					
			// Set the ContentLength property of the WebRequest.
			request.ContentLength = byteArray.Length;
					
			// Get the request stream.
			Stream requestStream = request.GetRequestStream ();     <------------hier steckt er dann beim 2 login request.......
					
			// Write the data to the request stream.
			requestStream.Write (byteArray, 0, byteArray.Length);
			// Close the Stream object.
			requestStream.Close ();
		}
				
		// Get the response.
		HttpWebResponse response = (HttpWebResponse) request.GetResponse();
		// Get the stream containing content returned by the server.
		Stream dataStream = response.GetResponseStream ();
		// Open the stream using a StreamReader for easy access.
		StreamReader reader = new StreamReader (dataStream);
		// Read the content.
		responseFromServer = "HTTP/" + response.ProtocolVersion + " " + response.StatusDescription + " ";
		responseFromServer += response.Headers.ToString();

		// Clean up the streams.
		reader.Close ();
		dataStream.Close ();
		response.Close ();
	}
 
	catch (WebException e)
	{
		throw CatchHttpExceptions(responseFromServer = e.Message);
	}
	catch (Exception e)
	{
		throw new Exception(responseFromServer = e.Message);
	}

	return responseFromServer;
}

S
stan Themenstarter:in
44 Beiträge seit 2005
vor 18 Jahren

fehler gefunden😉
habe beim request für session_id vergessen:

get_response.close()

jetzt klappt alles😉

cu

S
127 Beiträge seit 2004
vor 17 Jahren

SUPPER

DANKE, das du deine Lösung nochmal gepostet hast.

Ich hatte einen ähnlichen Fehler und es lag genau daran.