We have a Flex client and a server that is using the Spring/Blazeds project.
After the user logs in and is authenticated, the spring security layer sends a redirect to a new URL which is where our main application is located.
However, within the flex client, I'm currently using HTTPService for the initial request and I get the redirected page sent back to me in its entirety.
How can I just get the URL so that I can use navigatetourl to get where the app to go where it needs to?
Any help would greatly be appreciated. Thanks!
One solution would be to include a token inside a comment block on the returned page, for instance:
<!-- redirectPage="http://localhost/new-location" -->
then check for it's presence inside the HTTPService result handler. The token's value could then be used in your call to navigateToURL.
Another solution would be to examine the HTTP response headers and extract the value of the "Location" header using ActionScript. Consider using the AS3 HTTP Client lib.
From the examples page http://code.google.com/p/as3httpclientlib/wiki/Examples To determine the 'Location' header from the response:
var client:HttpClient = new HttpClient();
var uri:URI = new URI("http://localhost/j_security_check");
client.listener.onStatus = function(event:HttpStatusEvent):void {
var response:HttpResponse = event.response;
// Headers are case insensitive
var redirectLocation:String = response.header.getValue("Location");
// call navigateToURL with redirectLocation
// ...
};
// include username and password in the request
client.post(uri);
NOTE: AS3 HTTP Client depends on AS3 Core and AS3 Crypto libs.
You can also simply use the URLLoader class, no need for external code. One of the events it dispatches is HTTPStatusEvent.HTTP_RESPONSE_STATUS. Just plug into that and retrieve the redirected url:
urlLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, onHTTPResponseStatus);
private function onHTTPResponseStatus(event:HTTPStatusEvent):void
{
var responseURL:String = event.responseURL;
}
I am (successfully) using this code right now, so if it doesn't work for some reason, let me know.
Related
New to OData, I need to access SAP Odata Web Service that required Authentication and Token. Say I have the token hardcoded. How to add this token to Simple OData Client?
var settings = new Simple.OData.Client.ODataClientSettings();
settings.BaseUri = new Uri("https://..../UoM?$filter=wer eg '1000' &format=json");
settings.Credentials = new NetworkCredential("user1", "usrpwd");
var client = new ODataClient(settings);
Please kindly help me.
Update --
In this link : Simple Odata Client - How to add oAuth Token in each request header?
It didnot show how to add the hardcoded Token. For my problem, I need to add a given token and make a Odata Request. I check the Odata.org website, I dont seems to find any example for my case.
I have no experience on simple.Odata.client, Can some1 be kind enough to show me how.
Thanks
I believe you can use the ODataClientSettings.BeforeRequest action to alter the request before it is sent.
In the example below I set the Authorization header of the request to 'Bearer <Token>':
settings.BeforeRequest = req => {
req.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "Your_Token_Here");
};
Of course it is up to you to configure the request for you specific type of authentication.
The URL you use in your example is clearly wrong and not the OData URL for SAP.
You need the base URL for the "yourODataServiceRootURL" below and then add the relative path later in the ODataclient setting eg. "api/data/v9.1"
Instead of using the delegate method to intercept and add the Authorization header on every Http call, a clearer/cleaner solution is to instantiate the ODataClient with an HttpClient instance.
This also allows you to control the HttpClient lifecycle externally.
The code below is an extract of a .Net core app using an Azure AD OAuth2 token to connect to a Dynamics 365 OData Web API.
httpClient.BaseAddress = new Uri(yourODataServiceRootURL);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", yourBearerAccessToken);
//Use the httpClient we setup with the Bearer token header
var odataSettings = new ODataClientSettings(httpClient, new Uri("api/data/v9.1", UriKind.Relative));
var odataClient = new ODataClient(odataSettings);
I have looked at the other posts and none directly show this. I need to call a backend Suitelet from a userevent. I have created a generic backend suitelet that I need to call from multiple events, I have tried SS2 to call using https with a full qualified and a relational Suitelet URL and niether seems to work. The full qualified seems to go without error but then after the request does not enter the catch I put in place it veers off into NS library code and doesn't seem to call the Suitelet. Any help would be greatly appreciated. I have included code os the call.
var url = 'https://debugger.sandbox.netsuite.com/app/site/hosting/scriptlet.nl?script=1239&deploy=1';
var header = [];
header['Content-Type']='application/json';
var response = https.post( {
url : url
, header: header
, body : {
data: id
}
} );
You can only successfully call a Suitelet, which is available without login, from a server-side script. A Suitelet, which is not available without login, can be called from a client script as on client-side the authenticated session already exists. Perhaps a RESTlet would serve your scenario better? You can pass authentication headers when invoking the RESTlet. Otherwise, a custom module could hold the logic and be invoked from the different scripts.
Within my Owin Self hosted Web Api project I am trying to build a custom MediaTypeFormatter that inherits from BufferedMediaTypeFormatter.
But the problem is the HttpContent object passed into ReadFromStream(..) does not contain all the headers sent in the request.
How do you access ALL the headers that were sent in the request (I know this because I made the request), or access the original HttpRequestMessage in the ReadFromStream(..) method ?
This seams to be a major bug and I cannot think of any reason why all the Request headers are not provided.
Sounds like the ASP.NET Request object does not expose a property for the specific header field name you are looking for.
So it looks like first, you need the Request and to do that you might be able to override GetPerRequestFormatterInstance:
How do I retrieve the HTTP request method in an ASP.NET WebAPI MediaTypeFormatter?
Once you have the request object you can search for the specific header field name you are looking for like so:
IEnumerable<string> headerValues = request.Headers.GetValues("MyHeaderFieldName");
var id = headerValues.FirstOrDefault();
You can also get the raw request if needed:
Request.InputStream.Position = 0;
var input = new StreamReader(Request.InputStream).ReadToEnd();
Two things; first is I keep getting a 401 exception on the last line. I had thought that re-using the session would allow me to not only NOT have to resend the credentials but would also let me access the report by URL. It does neither...
Second, what do I do with the response once I have it to display it in the browser for the User?
This is what I have so far but I am unsure where to go with this from here....
var rs = new ReportExecutionService.ReportExecutionService();
rs.Credentials = new System.Net.NetworkCredential("UserID", "Pswd", "myDomain");
var execInfo = rs.LoadReport("/Nav Reports/OpenSalesOrderByCustomer", null);
var format = "HTML4";
string requestUri = string.Format(
#"https://reports.myServer.com/ReportServer/?{0}&rs:SessionId={1}&rs:Format={2}",
execInfo.ReportPath,
execInfo.ExecutionID,
format
);
WebRequest request = WebRequest.Create(requestUri);
request.UseDefaultCredentials = false;
request.Credentials = new System.Net.NetworkCredential("UserID", "Pswd", "myDomain");
var response = request.GetResponse();
For Background info -->
I am trying to setup Remote Report processing with SSRS on my asp.net web forms app. I would simply use the Report Viewer control but it's hideous looking and not acceptable to our user base. The URL Access returns a much better looking and formatted report and is acceptable but I have to pass Security Credentials. I would use SOAP API except it returns a non-styled html 'blob' and also removes the Toolbar functionality that we want to use.
So, I seem to be left with figuring out a way to use the SOAP API to authenticate a session and then somehow use that to use URL Access.
Just call the SOAP API, get the bytes, and return those bytes to the user with appropriate headers, content-type: application/pdf, content-disposition:attachment;filename=report.pdf. You don't need to do multiple calls to the report server.
I have a admin page in asp.net that adds data to a database. This database is available as a JSON string to external websites, however, since it's a lot of data, the external websites cache this data locally.
I want to be able to ping the external websites to let them know the data has changed so they can referesh their cache. I figure I can setup an ASHX handler that receives a parameter telling them what data has changed, so they can both delete that data and refresh it.
The only part I'm not sure about is the best way to call this external page from my admin page. Do I just do a regular WebRequest and discard the result? or is there a simpler way to call a page from code when you don't need the response?
Basically I just want to "ping" this page, so it knows it needs to refresh.
thanks!
If you just want to call the remote page, you can use the WebRequest class.
http://msdn.microsoft.com/en-us/library/debx8sh9.aspx
WebRequest request = WebRequest.Create("http://my.domain.ext/page.ashx");
using(WebResponse response = request.GetResponse()) {
response.Close();
}
If you want to do more advanced stuff a webservice would be more appropriate.
You could have a flag set up in the database. That would turn this into a much simpler task.
If no alternative exists you can use the WebClient class:
using (var wc = new WebClient())
{
wc.DownloadString(address);
}