I am interested in scripting a HTTP Request to a listening web service I wrote (for testing purposes). I want to do this in Powershell. Initiating a HTTP Request through telnet is easy enough.
telnet google.com 80
Then, after a socket is established I can type in the following HTTP Verb and file:
GET /search?q=test
This is equivalent to performing a google search for the word "test". Great! However, I need to provide a more detailed HTTP Request Header if I want to do something more interesting. I'm trying to do something very similar to the example found here: http://blog.tonycode.com/tech-stuff/http-notes/making-http-requests-via-telnet
Following the author's example from the previous site, I created a local file with the following contents:
echo "open $1 $2"
sleep 2
echo "GET $4 HTTP/1.0"
echo "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"
echo "Host: $3"
echo
echo
sleep 2
(This is similar to the custom HTTP Request Header I'd like to use for testing my own web services)
I then save this file as "getpage" (I also tried saving it as "getpage.sh"). I continue following the author's example and attempt to pipe the previous file into telnet from Powershell:
./getpage tonycode.com 80 tonycode.com /| telnet
However, Powershell is returning the following error:
Cannot run a document in the middle of a pipeline: ~\Desktop\getpage.
At line:1 char:1
+ ./getpage tonycode.com 80 tonycode.com /| telnet
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (~....Desktop\getpage:String) [], RuntimeException
+ FullyQualifiedErrorId : CantActivateDocumentInPipeline
I typed $PSVersionTable in Powershell and verified I'm using Powershell version 4.0. I'm starting to run out of ideas. I looked through the StackOverflow forums regarding http requests through telnet but I haven't found a good way to send a custom HTTP Request Header through telnet by passing in a pre-formated http header via a shell pipe. I can't really type the entire Http Request in telnet because 1) that defeats the purpose of scripting these kinds of things and 2) pressing the Enter key from telnet submits the current request before I can finishing typing the full Http Header. Does anyone have any suggestions how I can accomplish this in PowerShell? I can already write and send custom Http Headers in Firefox and it makes life way easier. I would just like to script this in Powershell if possible. Thanks in advance.
I am interested in scripting a HTTP Request to a listening web service I wrote (for testing purposes). I want to do this in Powershell.
then leave telnet alone :)
PowerShell(v3+) has built-in cmdlets:
Invoke-WebReques
Invoke-RestMethod
Or you can use System.Net.Sockets.TcpClient
Replacing Telnet.exe (now removed from Vista)
Scripting Network / TCP Connections in PowerShell
Or System.Net.WebClient
More advanced HTTP scripting: Facebook Photo Album Downloader
PS:
Using telnet to talk HTTP might have been "cool" in the past. But no one should be doing it nowadays. Especially when anything more than a trivial GET is required.
You should be using a real library for this like libcurl or whatever is available in your development environment.
Notes:
HTTP/1.0 is blocked by many sites nowadays. You should probably use HTTP/1.1.
HTTP/2 is a binary protocol. Using telnet or whatever "text" method you might have read about is just not possible with this protocol.
Related
I am using jbpm version 6.5.0. I have requirement to call process through REST API and I am successful to start process with parameters.
I am testing it with postman. The thing is that there is also requirement of document attachments on starting by REST API, for that I have followed link (https://access.redhat.com/solutions/2567701 ) but unsuccessful to attach document in same process. The REST API URI provided in followed link is
http://server:port/kie-server/services/rest/server/containers/{containerName}/processes/{processId}/instances this is not working . I am stuck with containerName in the link .
Secondly, I have confusion i.e. there are 2 uri which starts process on is for sending parameters on RESTAPI and other is for document attachment RESTAPI. Will both of the REST API called by the application which want to start process .
I have check following to check containerName but unsuccessful.
http://localhost:8080/kie-server/services/rest/server/containers running successfully with out containers list
http://localhost:8080/kie-server/services/rest/server running successfully
http://localhost:8080/kie-server/services/rest/server/containers/%7Bid%7D Failure with msg Container id is not instantiated
Kindly provide me solution or steps any tutorial which have clear steps to achieve the task .
I am not sure whether it is too late to answer now. Here it is anyway.
For the classic employee evaluation process example of jBPM documentation, the HTTP request to create a process instance looks like the following. "evaluation_1.0" is the process container id and "evaluation" is the process id/name.
POST /kie-server/services/rest/server/containers/evaluation_1.0/processes/evaluation/instances HTTP/1.1
Host: localhost:8080
Authorization: Basic {basic auth token}
Content-Type: application/json
Content-Length: 43
{"initiator": "<jbpm user name>", "employee":"<employee name>"}
`
This problem seems to exist on a specific server. All other servers are working ok.
Background: The website is basically Forms Auth but there's an asmx that manually requires Basic Auth.
I have two C# client.
When invoking using SOAP (asmx client proxy) with basic auth credentials - all is well.
When invoking using WebClient or WebRequest with the same basic auth credentials, I get 401.5.
The folders have "Everyone" set to them.
When setting up iis trace, I see a very weird behavior. The request arrives with the correct Basic auth header. But further down the trace I see the following:
GENERAL_REQUEST_HEADERS
Headers="Connection: Keep-Alive
Content-Length: 68
Content-Type: application/json
Authorization: Kerberos
Expect: 100-continue
Host: 1.2.3.4
The Kerberos seems very weird. It is as if the request headers changed throughout the process, and perhaps that explains the 401.5.
Again, I would like to stress out that on other servers there's no problem with both clients. The only difference I can think of is that the problematic server is a DC. But if that is a problem then why is the SOAP client working well?
Any ideas?
Progress!
After some debugging I noticed that Application_AuthenticateRequest was fired twice for every request. The first time with Basic auth as I expected and the second time with the Kerberos!
After googling I found this:
http://forums.asp.net/t/1868629.aspx?HttpModule+triggered+two+times+for+request+to+URL+without+default+document
Seems like for extensionless urls those events might fire multiple times, depending on the configured Extensionless urls.
Going back to the trace I noticed that in the non-working server the trace shows usage of ExtensionlessUrl-ISAPI-4.0_64bit, and in the working servers no such entry existed. After comparing the two IIS I noticed that the non-working IIS had ExtensionlessUrl-ISAPI-4.0_64bit configured whereas in the working IIS there was ExtensionlessUrl**Handler**-ISAPI-4.0_64bit (note the "handler"). I compared the dlls involved and the working server had a newer aspnet_isapi.dll. I assume that this is an updated extensionless url handler. I suppose an upgrade to IIS or .NET might install a later version, but for now I tried to remove the ExtensionlessUrl-ISAPI-4.0_xxbit like so:
<remove name="ExtensionlessUrl-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrl-ISAPI-4.0_64bit" />
And it worked! Now there is only a single Application_AuthenticateRequest.
The non-working version that had this in the trace:
OldHandlerName="", NewHandlerName="ExtensionlessUrl-ISAPI-4.0_64bit", NewHandlerModules="IsapiModule", NewHandlerScriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll", NewHandlerType=""
Now changed to:
OldHandlerName="", NewHandlerName="WebServiceHandlerFactory-ISAPI-4.0_64bit", NewHandlerModules="IsapiModule", NewHandlerScriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll", NewHandlerType=""
Hopefully that's the end of it. Additional testing still required.
I would appreciate if someone can write how to upgrade IIS dlls to a later version. Is this an upgrade to .NET or is there a specific KB update that is downloaded with Windows Update?
Recently I was forced to switch from SVN to TFS.
I'm trying to get this working with TEE on our RedHat box.
Any action seems to end with something like this:
user#rh: tf -map $/XX/XX . -workspace:app-job -server:http://tfs.domain.com:8080/tfs/TFS2008/ -profile:TFS1_PRF_C
Password:
An error occurred: Proxy URL 'incache.domain.com:8080' does not contain a valid hostname.
Could someone help with that?
Your question is a little vague about what you expect to happen here (are you supposed to be using an HTTP proxy to access your TFS server? Or is the problem that it's assuming your HTTP proxy?)
I'm going to assume that you do not need to use an HTTP proxy to access your internal TFS server, since in most corporate environments your proxy is used to get outside the network, not inside. By default, the Team Explorer Everywhere CLC does try to use your system HTTP proxy, however this is configurable in your connection profile.
In order to override your default system HTTP proxy for that profile, you can set the profile property httpProxyIgnoreGlobal to true:
tf profile -edit -boolean:httpProxyIgnoreGlobal=true TFS1_PRF_C
I'm trying to generate a Perl library to connect to a WebService. This webservice is in an HTTPS server and my user has access to it.
I've executed wsdl2perl.pl several times, with different options, and it always fails with the message: Unauthorized at /usr/lib/perl5/site_perl/5.8.8/SOAP/WSDL/Expat/Base.pm line 73.
The thing is, when I don't give my user/pass as arguments, it doesn't even asks for them.
I've read [SOAP::WSDL::Manual::Cookbook] (http://search.cpan.org/~mkutter/SOAP-WSDL-2.00.10/lib/SOAP/WSDL/Manual/Cookbook.pod) and done what it says about HTTPS: Crypt::SSLeay is instaleld, and both SOAP::WSDL::Transport::HTTP and SOAP::Transport::HTTP are modified.
Can you give any hint about what may be going wrong?
Can you freely access the WSDL file from your web browser?
Can someone else in your network access it without any problems?
Maybe the web server hosting the WSDL file requires Basic or some other kind of Authentication...
If not necessary ,I don't recommend you to use perl as a web service client .As you know ,perl is a open-source language,although it do support soap protocol,but its support do not seem very standard.At first,its document is not very clear.And also ,its support sometimes is limited.At last,bug always exists here and there.
So ,if you have to use wsdl2perl,you can use komodo to step into the code to find out what happened.This is just what I used to do when using perl as a web service client.You know ,in the back of https is SSL,so ,if your SSL is based on certificate-authorized,you have to set up your cert path and the list of trusted server cert.You'd better use linux-based firefox to have a test.As I know ,you can set up firefox's cert path and firefox's trusted cert list.If firefox can communicated with your web service server succefully,then,it's time to debug your perl client.
To debug situations with Perl and SOAP, interpose a web proxy so you can see exactly what data is being passed and what response comes back from the server. You were getting a 401 Not authorized, I expect, but there may be more detail in the server response.
Both Fiddler http://docs.telerik.com/fiddler and Charles proxy https://www.charlesproxy.com/ can do this.
The error message you quote seems to be from this line :
die $response->message() if $response->code() ne '200';
and in HTTP world, Unauthorized is clearly error code 401, which means your website asks for a username and password (most probably, some website may "hijack" this error code to cater for other conditions like a filter on the source IP).
Do you have them?
If so, you can
after wdsl2perl has run, find in the created files where set_proxy() is called and change the URL in there to include the username and password like that : ...->set_proxy('http://USERNAME:PASSWORD#www.example.com/...')
or your in code, after instantiating the SOAP::WSDL object, call service(SERVICENAME) on it (for each service you have defined in your WSDL file), which gives you a new object, on which you call transport() to access the underlying transport object on which you can call proxy() with the URL as formatted above (yes it is proxy() here and set_proxy() above); or you call credentials() instead of proxy() and you pass 4 strings:
'HOSTNAME:PORT'
the realm, as given by the webserver but I think you can put anything
the username
the password
Is it possible to perform request to https using http-request phing task?
If no - what workaround could you propose? wget?
Yes, you are not limited to HTTP only - HTTPS works fine.
Examples are shown in the phing documentation:
<http-request url="https://accounts.google.com/"/>
Alternatively, you can use the curl adapter:
<http-request url="https://accounts.google.com/" verbose="true">
<config name="adapter" value="HTTP_Request2_Adapter_Curl"/>
</http-request>
It seems that by default you won't be able to connect using https. This is because the Phing http task uses the PEAR HTTP_Request2 libraries to make the connection. That in turn uses either PHP curl or sockets to make the connection. When connecting to https it needs to verify the CA certificate. That can be switched off so any certificate is supported but the Phing task doesn't support passing the option over to HTTP_Request2.
So if you otherwise like the Phing http task I suggest you either copy and modify the task or write your own that extends the original one so it supports the ssl_verify_peer option.
Or you can always default to the exec task and fetch whatever you need using curl of wget which however might not work on multiple platforms.
Here are links where you find more info:
PEAR HTTP_Request2 configuration options
Source code of the Phing http task
HTTP_Request2 info about https and proxy servers (Search for https)
How to write your own Phing task