I am trying to pass api request and get a response on button click in Asp.net 4.61 with VB.net. Then the response will show in a textbox, however I never get a response and it doesnt even seem my login is hitting the API as no attempts show up in the API log. I had something like this working the other day and my stupid hard drive died! Trying to rewrite it but I have missed something clearly. I do not get any errors just no response.
I am able to use postman and get a response to the same url
thanks i advance here is a sample of my code
Imports Newtonsoft.Json
Imports RestSharp
Imports System
'Imports System.Text.Json
'Imports System.Text.Json.Nodes
Imports System.Threading.Tasks
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim restClient As RestClient = New RestClient("http://myurl.com/ws/rest/userid=myid&password=password")
' restClient.Timeout = -1
Dim request As RestRequest = New RestRequest(Method.Post)
request.AddHeader("X-API-Key", "MYAPIKEY")
request.AddHeader("Content-Type", "application/xml")
Dim body = "MY Body Request XML Redacted"
request.AddParameter("application/xml", body, ParameterType.RequestBody)
Dim result As RestResponse = restClient.Execute(request)
MsgBox((result.Content))
txtXMLTEXTBoxTest.Text = result.Content
End Sub
Related
How to set httphandler from httpmodule for static file that is not present in poject.
Eg: If client requests a file called abc.xml thats not in my project,I need to add handler from my httpmodule and send some response to client how do i do it. My handler does not get called after adding it from httpmodule.
My HttpModule Code is as given below:
Public Sub Context_BeginRequest(sender As Object, e As EventArgs)
Dim Application As HttpApplication = CType(sender, HttpApplication)
Dim CustomHandler As StorageHandler = New StorageHandler()
Application.Context.Handler = CustomHandler
End Sub
The processrequest in customHandler does not get executed.
After spending good 5hr, Got it .
Need to use RemapHandler,
Application.Context.RemapHandler(CustomHandler)
and not
Application.Context.Handler = CustomHandler
We have an old Asp.net 2.0 web service where I need to put in a simple HTTP response. In the below code, the function "APIValidation()" returns an int, 200 or 404. All I need to do is have it send an HttpResponse so my node web app can read the statuscode (and then do what it needs to do).
I have no idea how to do this (I'm a noob with ASP), the tutorials I find are too elaborate, it seems this could be solved in a few lines of code, I just don't know which.
You can see it in action here:
200 : http://registration.imprintplus.com/imprinttest/GlobalSrvSN.aspx?sn=29820C0792024CDC8D590BF14AF42490
404: http://registration.imprintplus.com/imprinttest/GlobalSrvSN.aspx?sn=invalid
The other option is for Node to be able to extract the 200 or 404 out of what the ASP service gives me. Either or works for me.
Option Explicit Off
Option Strict Off
Imports ActivationServer
Partial Class GlobalSrvSN
Inherits System.Web.UI.Page
Public Function APIValidation(ByVal sn As String, ByVal databaseSource As String) As String
Dim act As New LogicProtect_ActivationServer(databaseSource)
Return act.APIValidation("user", "user#company.com", sn)
End Function
End Class
thanks a million!
Unsure how you're calling that function so will assume a few things if that's the only code you have.
If you're calling it from the .aspx file then this would be an example:
<%# Page Language="vb" ....." %>
<%
Dim foo = APIValidation(Request("sn"), "other string")
Response.StatusCode = CInt(foo)
%>
If from "code behind" ([page].aspx.vb):
Option Explicit Off
Option Strict Off
Imports ActivationServer
Partial Class GlobalSrvSN
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim foo = APIValidation(Request("sn"), "other string")
Response.StatusCode = CInt(foo)
End Sub
Public Function APIValidation(ByVal sn As String, ByVal databaseSource As String) As String
Dim act As New LogicProtect_ActivationServer(databaseSource)
Return act.APIValidation("user", "user#company.com", sn)
End Function
End Class
Notes: Above is a very trivial answer to keep things simple. But:
above is really a "Web Forms Page" (not technically a "web service") which would be asmx (2.0)
Skipped any input validation (queryString), error checking/handling.
Response object is how you'd control HTTP Responses (headers, etc.)
Hth
I have run into a problem in my asp.net and vb.net programming. I have made a website which connects to a database to authenticate users. I have made another page which my windows form application uses to authenticate users so the program does not have to connect directly to the MySql Database as this is insecure.
So far, the code for my asp.net page is:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If Request.QueryString.Keys(0) = "key" And Request.QueryString.Keys(1) = "getapikeyv1" And Request.QueryString.Keys(2) = "authapienc2" Then
Dim key As String = Request.QueryString.Get("key")
If key = "dua9r3rqpK{WPDWp9r93af03r8yqrEPIF{A}W~DW)D08q3raewdawdug9q8wdyaw9wq" Then
returnLabel.Text = "XYeJay4XVh6amvf1kJ34Y6y6hR0sSokP9oJFsi0Mxl4QB0T86W0iac9o2nRfCmFmsONq6sPz+rdX+/NqFk3inHRGnwnqf0IsQXE/M/SvnvY="
Else
returnLabel.Text = "invk"
End If
Else
returnLabel.Text = "invalidrequest"
End If
End If
End Sub
The default value for 'returnLabel' is INVALIDREQUEST. My api keys defined above are working fine so are not needed to be considered here. However, when I use the following code to communicate with the webpage, it always returns with returnLabel's value as 'INVALIDREQUEST'. Even if I put the returnLabel.Text = "1233" at the beginning of the Me.Load sub, the page still returns INVALIDREQUEST when I communicate with it through my program!
I use this code to request:
Try
Dim APIRequest As New WebClient
APIRequest.QueryString.Add("key", r9j0wqfha0fh0wf0.DecryptString128Bit(APIKey5, dVadaihwdq93ra0w0))
APIRequest.QueryString.Add("getapikeyv1", "")
APIRequest.QueryString.Add("authapienc2", "")
Dim ako39rqwfa As String = APIRequest.DownloadString(EncryptionPageUrl)
MsgBox(ako39rqwfa)
Dim m As Match = Regex.Match(ako39rqwfa, "<span id=""returnLabel"">.*?</span>")
APIKey00 = m.Value.Replace("<span id=""returnLabel"">", "").Replace("</span>", "")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
As you can see, the WebClient I use is fine but the Me.Load sub in the webpage is not responding the request made by the program...
Is there any way I can make the webpage respond to the WebClient.DownloadString() function?
Thanks,
Rodit
(ps. c# or vb code would be appreciated)
Change your asp.net page to check the query string like this, not sure if you can assume they are in a certain order:
If Request.QueryString.Get("key") isnot nothing And
Request.QueryString.Get("getapikeyv1") isnot nothing And
Request.QueryString.Get("authapienc2") isnot nothing Then
I am currently developing a asp.net webpage and a WCF publish subscribe service. The WCF service has been done up the subscriber is a winform app which is also done up. I am now trying to get the asp.net webpage to connect to my publish service for my WCF. However there is an weird error that I am getting. I have added the app.config and the generatedProxy.cs.vb to my asp.net project.
This is the code for my class
Public Class json
Implements IPostingContractCallback
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.ContentType = "application/json"
If Request.QueryString("action") = "postAlert" Then
Dim site As InstanceContext = New InstanceContext(New json())
Dim client As PostingContractClient = New PostingContractClient(site)
client.PublishPost("testing")
client.Close()
End If
End Sub
Public Sub PostReceived(ByVal postSampleData As String)
Console.WriteLine("PostChange(item {0})", postSampleData)
End Sub
the sub PostReceived is the callback method for my WCF service. It practically is meant to be do nothing as this is the Publisher, but I still have to implement it due to the WCF standards. The error that I am getting is
Class 'json' must implement 'Sub PostReceived(postSampleData As String)' for interface 'IPostingContractCallback'
How come i am getting the error when i have already implemented the sub as stated above?
Method signature must be: (Take a look at VB.NET Interfaces)
Public Sub PostReceived(ByVal postSampleData As String) Implements IPostingContractCallback.PostReceived
Console.WriteLine("PostChange(item {0})", postSampleData)
End Sub
I have a asp.net c# web application with contains reports in remote processing mode. I am using the report-viewer control to render the reports. When I run the application in debug mode, I'm able to view my reports however when I publish the application to a different server I get this error message:
The request failed with HTTP status 401: Unauthorized.
My report server is on a different server than the location of my published web application. I have added new role assignment to my report server and also added to my web.config but the error persists. I think I am missing something in my aspx page for reportviewer.
Any input would be appreciated.
I'm assuming you already have set the server in your codebehind such as this
reportviewer.ServerReport.ReportServerUrl = "http://{server_ip}/reportserver";
or via the properties of the report viewer control. Make sure you change {server_ip} to the actual for the report server.
Other such problems I've seen in the past have to do with access for individual reports. Since this is cross-server, you'll need a proxy user set to view the reports.
Here are 2 examples from MSDN:
Example 1
Example 2
Yes! use Page_Load & Page_Init in this way
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ReportViewer1.Visible = True
Dim strReportsFolder As String = ConfigurationManager.AppSettings("ReportsFolder")
Dim reportName As String = "report1"
ReportViewer1.ServerReport.ReportPath = strReportsFolder + reportName
End Sub
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs)
PopulateReport(ReportViewer1, "")
End Sub
Public Shared Sub PopulateReport(ByVal rptViewer As ReportViewer, ByVal reportName As String)
Dim strReportServer As String = ConfigurationManager.AppSettings("ReportServer")
Dim strUserName As String = ConfigurationManager.AppSettings("Username")
Dim strPassword As String = ConfigurationManager.AppSettings("Password")
Dim strDomain As String = ConfigurationManager.AppSettings("Domain")
rptViewer.ServerReport.ReportServerUrl = New Uri(strReportServer)
rptViewer.ServerReport.ReportServerCredentials = New ReportViewerCredentials(strUserName, strPassword)
End Sub