All,
I am trying to access a restful API via PowerShell. The API requires several non-standard headers so I am using the $request.Headers.Add() syntax.
I am getting a (500) Internal Server error so I know I am nowhere close.
I can't use WireShark because the endpoint is Https.
How can I build a HttpWebRequest object in PowerShell and view the Raw XML?
Here is the simple code:
$concat = EncodeBase64("$($username)#$($org):$($password)")
$request = [System.Net.HttpWebRequest]::Create($URL);
$request.Method = "POST";
$request.ContentType = "application/vnd.vmware.vcloud.session+xml;version1.5";
$request.Headers.Add("x-vcloud-authorization", $concat);
Thanks!
Go grab Fiddler and read up on how to use it to view https traffic.
Related
I am trying to emulate the following curl command in c# using RestSharp:
curl URL -F "login=samplelogin" -F "key=password"
I am using the following c# code to format the request:
// Configure Request
RestRequest request = new RestRequest(resource, Method.POST);
request.AddParameter("login", context.Control.CourtLogin, ParameterType.RequestBody);
request.AddParameter("Key", context.Control.CourtPassword, ParameterType.RequestBody);
request.AddHeader("Content-Type", "multipart/form-data");
The client endpoint just returns login failure. When I read the documentation for AddParameter on the RestRequest class. It states you can only have key value pair with parameter type = RequestBody.
Does anyone have any ideas on how to get multiple form data key value pairs in a RestSharp client request? Or how to duplicate multiple -F curl options using RestSharp?
Thanks in advance!
"Content-Type" should be "application/x-www-form-urlencoded".
I am using this erlang-package on Github to work with WSDL and SOAP, and I am only using the package for Client generation! I have not erlang knowledge at all - only basic elixir.
My Problem:
How can I send a request with an authorization header?
Lets say the code to test my service looks like the following:
connectionCheck() ->
'WsdlService_client':connectionCheck(
#'P:connectionCheck'{
clientSoftwareKennung = "Elixir"},
_Soap_headers = [],
_Soap_options = [{url,"http://localhost:8091/myservice/v2.0/connectionCheck"}]).
Which parameter needs to be filled in and what do the parameters look like when I need the following header in the resulting http-request?
Authorization: Basic <placeholder encodeded user password>
Thanks!
I was able to solve it by myself.
If you need to pass some http-Headers to your Soap-Request you can do it like that:
_Soap_options = [{url,"http://localhost:8091/myservice/v2.0/connectionCheck"},{http_headers, [{"Authorization","Basic Encoded User-Pass"}]}]).
We are trying to download search results from Splunk using the below mentioned Rest API endpoint through PowerShell Invoke-RestMethod and Invoke-WebRequest methods(both work). But some of our searches run for longer than 5 minutes due to which no data is returned to be written into a local file by Powershell's Invoke-RestMethod and Invoke-WebRequest methods and hence requests are timed out exactly after 5 mintues. We want to increase the ReadWriteTimeout mentioned on https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.readwritetimeout(v=vs.110).aspx page for Powershell's Invoke-RestMethod and Invoke-WebRequest methods, is it possible?
Splunk Rest API Endpoint:
https://${server}:port/services/search/jobs/export
NOTE:- This Splunk endpoint starts streaming results after completing the search only.
Many might suggest to use another CURL client for making this Rest API call, we have already tried that and it's working since other clients like curl in Cygwin don't have the default 5 minute ReadWriteTimeout.
No, but you can directly use the HttpWebRequest object you referenced instead.
I would recommend writing your own function Invoke-MyRestMethod that uses that class with parameters for R/W timeout and anything else you need.
The MSDN page on Invoke-WebRequest indicates that there's a -TimeoutSec parameter that takes an int32. It appears that Invoke-RestMethod supports the same parameter.
I need to consume a WS that requires client (machine) certificate. More precisely it uses WS-Security : SOAP Message Security, WS-Security : X.509 Certificate Token Profile as defined by http://docs.oasis-open.org/wss-m/wss/v1.1.1/os/wss-SOAPMessageSecurity-v1.1.1-os.html
Using the native consumer, Domino don't add (magically) the authentication in the SOAP header. Now how I'm supposed to do add the security in header? Ideally in LotusScript...
I don't see anyway to embed the Consumer in my own header or enrich the existing consumer. I join the IBM response on this.
So my question:
Is there a work around to do this in Lotusscript ?
did some of you done something like this in java (and I will probably make an LS2J since a lot of LotusScript code already exists when I will get (hopefully) the response from the WS
IBM response:
We understand that you are attempting to use SOAP header for authentication. Unfortunately this is currently not supported.
For your reference, we have at least two Enhancement Requests (that I could find in this area) that are related to this topic:
SPR # SODY9H6BTM: Creating Your Own Soap Objects Does Not Support Client Certificate Authentication In A Web Agent.
SPR # JSHN7A3MLP: Authentication data in the Header element of WS Consumer SOAP envelopes
Unfortunately there is nothing further we can do in Support at this time.
If I understood your problem correctly you do not know how to deal with SOAP header and if so there are 2 things you may want to know:
1) Passing session using native Domino consumer approach. See example below
TestServiceLocator service = new TestServiceLocator();
TestPort port = service.getTestPort();
// that would tell to save cookie session between calls
((javax.xml.rpc.Stub)port)._setProperty(javax.xml.rpc.Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
2) If it does not work for you, you may try to use native SOAP approach. I've blogged about that recently: SOAP and passing session
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// connect to webserivce
SOAPMessage soapResponse = soapConnection.call(connect(username, password), url);
// read cookie from response and use it when send another requests
MimeHeaders session = soapResponse.getMimeHeaders();
String sesisonCookie = session.getHeader("Set-Cookie")[0];
SOAPMessage soapResponse2 = soapConnection.call(customerGetAll(sesisonCookie), url);
soapConnection.close();
and than imagine you are in customGetAll method
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("Customer_GetAll", "m");
soapMessage.getMimeHeaders().addHeader("Cookie", sesisonCookie);
soapMessage.saveChanges();
Hope it will help.
I was using HTTP::Daemon to create a http server for my API. With the help of following example and doc, I was able to create a basic HTTP server.
However, my API should accepts JSON as a body in post request to the server. So, I need to read the JSON so that I can process it. I know, how to read url param $r->uri->query_form();
Is there a way to read POST JSON?
use JSON;
use Data::Dumper;
my $json = decode_json($r->content);
print Dumper $json;