c# - Is there another solution to WebResponse 403 error? -
c# - Is there another solution to WebResponse 403 error? -
there many posts on webresponse 403 error situation little different. have created console application run task on server. console application passes user emails in webrequest , waits webresponse receive uri returning parameters. code below worked few days ago 1 of other programmers added new parameter homecoming web address. know fact causing 403 error because if paste uri in ie new parameter works. since have console application homecoming web address cannot do, @ to the lowest degree don't think so.
unfortunately programmer said cannot alter , said there way receive uri or entire page content , can process way. still have no clue talking because streamreader requires webresponse , pretty much other solutions think of.
even though 403 error response still has uri parameters need because can see in ie in web address. need response uri. appreciate help have offer. below method giving me problems.
string employeeinfo = ""; seek { httpwebrequest request = (httpwebrequest)webrequest .create("http://example.com/subsub.aspx?instprod=xxx&vabid=emailaddress"); using (httpwebresponse webresponse = (httpwebresponse)request.getresponse()) //error occurs here. 403 forbidden { uri myuri = new uri(webresponse.responseuri.tostring()); string queryparamerter = myuri.query; employeeinfo = httputility.parsequerystring(queryparamerter).get("vres"); if (employeeinfo != "n/a") { homecoming employeeinfo; } else { employeeinfo = "0"; homecoming employeeinfo; } } } grab (webexception) { employeeinfo = "0"; homecoming employeeinfo; }
let's follow jim mischel's idea. we'll handle webexception , utilize response property of exception.
string employeeinfo = ""; seek { httpwebrequest request = (httpwebrequest)webrequest.create("http://example.com/subsub.aspx?instprod=xxx&vabid=emailaddress"); using (httpwebresponse webresponse = (httpwebresponse)request.getresponse()) //error occurs here. 403 forbidden { uri myuri = new uri(webresponse.responseuri.tostring()); string queryparamerter = myuri.query; employeeinfo = httputility.parsequerystring(queryparamerter).get("vres"); if (employeeinfo != "n/a") { homecoming employeeinfo; } else { employeeinfo = "0"; homecoming employeeinfo; } } } grab (webexception ex) { httpwebresponse response = ex.response httpwebresponse; if(response.statuscode != httpstatuscode.forbidden) { throw; } uri myuri = new uri(response.responseuri.tostring()); string queryparamerter = myuri.query; employeeinfo = httputility.parsequerystring(queryparamerter).get("vres"); if (employeeinfo != "n/a") { homecoming employeeinfo; } else { employeeinfo = "0"; homecoming employeeinfo; } }
c# .net webrequest
Comments
Post a Comment