MSXML2.XMLHTTP Request to validate entered URL in ASP Classic - http

Thanks in advance for any help received.
I want to allow our client to enter a URL into a text field which then checks whether the URL exists and works.
There are 3 possible outcomes I want to check for:
A status of 200 - OK,
A status of 500 - Server Error,
Or a status of 404 - page not found.
When executing the following code in ASP classic I get a status code of 12007 when I should be getting 404. Is this because it can't find a webserver to return a code of 404?
Function CheckURL(vURL)
ON ERROR RESUME NEXT
Set oXML=Server.CreateObject("MSXML2.XMLHTTP") : oXML.Open "POST",vURL,false : oXML.Send()
CheckURL = oXML.status
Set oXML = nothing
End Function
Or is something amiss here. What status codes am I likely to see other than the standard mentioned above.

The 12007 is a Windows HTTP error which means name hasn't been resolved. You can't get a 200, 404, 500 or any such thing if the host name can't be resolved to an IP address or a connection can't be established to that IP address. In these cases you will get error codes in the 12000s range which aren't HTTP status codes but are windows exception numbers.
See this list for a list of these exception numbers.
BTW, XMLHTTP is not a safe item object to use in ASP. Also why are you using a POST? This is the code I would use:-
Function CheckURL(vURL)
On Error Resume Next
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.3.0")
xhr.Open "HEAD", vURL, false
xhr.Send
CheckURL = xhr.status
End Function
Using HEAD allows you test the URL without actually downloading a potentially large entity body.

Related

Angular 2 always returns http status code 200 on this.http.get() even if the file doesn't exist

i'm trying to check if a pdf file exists on the server with an HTTP get request,for that i am testing if the status code returned by the server's response is different then 200, the problem is that i always get status code 200 and statusText "OK".
here's my Service class
getPdf(year: number,type: number, num: number): boolean{
this.http.get('http://localhost:4200/app/pdfs/'+year+'/'+type+'/'+num+'.pdf')
.subscribe(data => console.log(data));
return true;
}
in my component i have this code :
ngOnInit(){
this.pdfService.getPdf(2016,71015,1275);
}
and that's the result i get in Chrome dev tools console
any ideas of why that is happening and how i can check the existance of a file if this method is not applicable?
I think your server is redirecting some or all requests for assets not found to your main page. It is somewhat common for a single page app. You need to update your server configurations to make it return a not found response for some folders at least.

HttpWebRequest received error 406 and Fiddler seems to have confused things

I am using the following code....
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(PostingUrl), HttpWebRequest)
myHttpWebRequest.Method = "POST"
myHttpWebRequest.Headers.Add("Authorization", "Bearer " & RSettings.access_token)
myHttpWebRequest.Headers.Add("Accept-Version", "2")
myHttpWebRequest.ContentType = "application/json; charset=UTF-8"
myHttpWebRequest.Accept = "application/json"
' myHttpWebRequest.Proxy = Nothing ' ** SEE NOTES ON THIS LINE **
Dim Byt As Byte() = Encoding.UTF8.GetBytes(DataString)
Using stream = myHttpWebRequest.GetRequestStream()
stream.Write(Byt, 0, Byt.Length)
End Using
Using myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Using srRead As New StreamReader(myHttpWebResponse.GetResponseStream())
ListingResponse = srRead.ReadToEnd()
End Using
End Using
Where:
PostingUrl is "https://reverb.com/api/listings"
RSettings.access_token is (obviously) my access token for this API
DataString is a JSON string posting the data to the Reverb API
If I run my code from Visual Studio (localhost) it returns
The remote server returned an error: (406) Not Acceptable.
Trying to figure out why, I opened Fiddler hoping I could inspect content types and figure out the problem, but the response error changed to:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
(I'm guessing from this error that I also have an issue with my Auth key, but that's a separate subject I think.)
After a bit of Googling and S/O pages I found two suggestions:
Tools > Fiddler Options > HTTPS and uncheck "Capture HTTPS CONNECTs"
Add the commented out line: myHttpWebRequest.Proxy = Nothing
If I make any of those changes, I get back to my Error 406 that I get without Fiddler running.
However, if I add myHttpWebRequest.Proxy = Nothing line added, I can no longer see the Tunnel to http://reverb.com:443 Log entry in Fiddler, there's no record of a request to Reverb.com so I can't inspect anything.
I'm now very confused about what I'm doing, and I guess haven't actually made any progress at all!
I still have error 406 and don't seem to be able to inspect the headers/content type issues with Fiddler as I had hoped (please explain how if I am wrong!)
Even if I do correct the 406, I think I have an authentication error.
By the way... all this is an attempt to recreate the cURL example on the Rever docs page here:
https://dev.reverb.com/docs/create-a-listing
I have also been discussing this issue here:
https://dev.reverb.com/v1.0/discuss/57bb2ca0aa8f760e004588cf
Argh... well, my confusing over Fiddler still stands but the 406 error was caused by this:
myHttpWebRequest.Headers.Add("Accept-Version", "2")
Should have been
myHttpWebRequest.Headers.Add("Accept-Version", "2.0")
How simple!!

DotNetNuke - First request returns 404

I am having an issue with DotNetNuke platform that I cannot understand for the life of me... Google and SO searches have been no help.
The very first time any user tries to hit the site, regardless of the URL they are requesting, they are redirected to the URL below, and given the 404 error shown below. After that initial 404, if the user requests that exact same URL, everything works perfectly for that user going forward. They are redirected to the correct login page and everything works correctly from that point forward.
Does anyone know why this would only happen on the very first request to the site for each user? I have a Development, Test and Production environments set up, and the issue is consistent across all environments.
Requested URL: http://intranet.domain.com/page
Redirected URL: http://intranet.domain.com/Login.aspx?ReturnUrl=/DesktopModules/AuthenticationServices/ActiveDirectory/WindowsSignin.aspx
Server Error in '/' Application.
The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /Login.aspx
IIS: v7
DNN: v7.02.01
Default DNN authentication is disabled and Active Directory Authentication module is enabled. (v5.0.6)
Please let me know if there is any other configuration information I can provide.
This is not a full solution however it should help shed some light on the situation. I experienced the same issue. I would go to the website and it would redirect me to
WebsiteLinkHere/DesktopModules/AuthenticationServices/ActiveDirectory/WindowsSignin.aspx
On removal of the
DesktopModules/AuthenticationServices/ActiveDirectory/WindowsSignin.aspx
it would take me to my homepage and everything acted as expected from there on out. I grabbed the latest sourcecode from github for this module and started debugging. I traced the error down to the DNNUserController.ValidateUser() function. This seems to be returning nothing which then causes the page to error out. I decided to add a bandaid fix for the time being which may help others.
Within the WindowsSignin.aspx.vb file I added a try catch around
objAuthentication.AuthenticationLogon()
Within the catch statement I added the code that is used to redirect you after a successful authentication to the page you came from.
Try
objAuthentication.AuthenticationLogon()
Catch
Dim querystringparams As String = "logon=" & DateTime.Now.Ticks.ToString()
Dim strUrl As String = DotNetNuke.Common.NavigateURL(DotNetNuke.Entities.Portals.PortalSettings.Current.ActiveTab.TabID, String.Empty, querystringparams)
If Not HttpContext.Current.Request.Cookies("DNNReturnTo") Is Nothing _
Then
querystringparams =
HttpContext.Current.Request.Cookies("DNNReturnTo").Value
'ACD-8445
If querystringparams <> String.Empty Then querystringparams = querystringparams.ToLower
If querystringparams <> String.Empty And querystringparams.IndexOf("windowssignin.aspx") < 0 Then _
strUrl = querystringparams
End If
HttpContext.Current.Response.Redirect(strUrl, True)
End Try
This is not an elegant solution however it does escape the issue of the user's initial visit to the site being an error screen. Everything else seems to work as expected after the initial visit.
I finally found the answer over two years later...
The problem was solved by commenting out "add name="Authentication" ..." line in web.config. This disabled autologin feature completely.
http://www.dnnsoftware.com/forums/threadid/459907/scope/posts/site-redirecting-to-desktopmodules-authenticationservices-activedirectory-windowssigninaspx

Request.Form between HTTP and HTTPS pages in ASP.NET

I have a strange situation and google isn't helping me out. I have an admin site which is in simple HTTP who posts data to a different site running under HTTPS. The HTTP admin site (which I don't have direct access to) is sending the info via basic POST, and I'm trying to capture the Request.Form values in the HTTPS site. It works perfectly well in dev, due to the fact that the receiving site isn't running under SSL, but in prod, I have the Request.Form as empty. Someone could enlighten me? The basic HTTPS request code is below:
Dim nvm As NameValueCollection = Request.Form
Dim _idInscricao As String
Dim _Origem As String
litMensagem.Text = "Wait..."
If nvm.Keys.Count = 0 Then
litMensagem.Text = "Error recovering data. No keys found."
Exit Sub
End If
For Each _Key As String In nvm.Keys
If _Key.ToLower.EndsWith("idinscricao") Then
_idInscricao = nvm(_Key)
End If
If _Key.ToLower.EndsWith("origem") Then
_Origem = nvm(_Key)
End If
Next
If _idInscricao Is Nothing OrElse String.IsNullOrEmpty(_idInscricao) _
OrElse _Origem Is Nothing OrElse String.IsNullOrEmpty(_Origem) Then
litMensagem.Text = "Error recovering data."
Exit Sub
End If
I found this question because I was having the same problem, and I need to thank dana for the fiddler recommendation.
Using Fiddler, I found out what was going on. My page was on HTTPS, and the form that I was posting posted to HTTP. I couldn't figure out why my form structure on the posted page was empty.
Turns out the server couldn't find the http version of the file and did an automatic redirect to the https version, doing a GET with my form variables. They aren't available in the form scope with a GET. (FWIW, I'm using CFML.)
Once I changed the form action to post to HTTPS, everything worked like a charm.
-jason

ORA-29270: too many open HTTP requests

Can someone help me with this problem that occurs whenever you run a TRIGGER, but works in a normal PROCEDURE?
TRIGGER:
create or replace
procedure testeHTTP(search varchar2)
IS
Declare
req sys.utl_http.req;<BR>
resp sys.utl_http.resp;<BR>
url varchar2(500);
Begin
url := 'http://www.google.com.br';
dbms_output.put_line('abrindo');
-- Abrindo a conexão e iniciando uma requisição
req := sys.utl_http.begin_request(search);
dbms_output.put_line('preparando');
-- Preparandose para obter as respostas
resp := sys.utl_http.get_response(req);
dbms_output.put_line('finalizando response');
-- Encerrando a comunicação request/response
sys.utl_http.end_response(resp);
Exception
When Others Then
dbms_output.put_line('excecao');
dbms_output.put_line(sys.utl_http.GET_DETAILED_SQLERRM());
End;
close your user session and then the problem is fixed.
Internal there is a limit from 5 http requests.
Might a problem is the missing: utl_http.end_response
or an exception in the app and not a close from the resp object.
modify the code like that:
EXCEPTION
WHEN UTL_HTTP.TOO_MANY_REQUESTS THEN
UTL_HTTP.END_RESPONSE(resp);
you need to close your requests once you are done with them, it does not happen automatically (unless you disconnect form the db entirely)
It used to be utl_http.end_response, but I am not sure if it is the same api any more.
Usually we need UTL_HTTP.END_RESPONSE(resp); to avoid of ORA-29270: too many open HTTP requests, but I think I reproduced the problem of #Clóvis Santos in Oracle 19c.
If web-service always returns status 200 (success) then too many open HTTP requests never happens. But if persistent connections are enabled and web-service returns status 404, behavior becomes different.
Let`s call something that always return 404.
First call of utl_http.begin_request returns normally and opens new persistent connection. We can check it with select utl_http.get_persistent_conn_count() from dual;. Second call causes an exception inside utl_http.begin_request and persistent connection becomes closed. (Exception is correctly handled with end_response/end_request).
If I continue then each odd execution returns 404 normally and each even execution gives an exception (handled correctly of course).
After some iterations I get ORA-29270: too many open HTTP requests. If web-service returns status 200 everything goes normally.
I guess, it happens because of the specific web-service. Probable it drops persistent connection after 404 and doesn't after 200. Second call tries to reuse request on persistent connection but it doesn't exist and causes request leak.
If I use utl_http.set_persistent_conn_support (false, 0); once in my session the problem disappears. I can call web-service as many times as I need.
Resolution:
Try to switch off persistent connection support. Probable, on the http-server persistent connections work differently for different requests. Looks like a bug.

Resources