While writing karate feature test for websockets i am getting Invalid handshake response while the same endpoint is working when executed with postman.Here is karate feature test
Background:
* def accessTokenKey = call read('PostmanRequest.feature')
* def AuthToken = accessTokenKey.response.access_token
Scenario: getAccounts using txt
* def socket = karate.webSocket('wss://api-ws-priv.eem.sit.bank.ikano/csp-v1
action=searchCounterParty&authtoken=' + AuthToken)
* def requestdata = read('classpath:testData/getAccountsRequest.txt')
* socket.send(requestdata)
* def result = socket.listen(5000)
* json jsonResult = result
* print jsonResult.event.payload.operation
* match jsonResult.event.payload.operation.operationCode == '200'
The error response we are getting is this:
14:26:39.336 websocket client init failed: Invalid handshake response getStatus: 403 Forbidden
14:26:39.361 src/test/java/Features/getAccounts.feature:16
* def socket = karate.webSocket('wss://api-ws-priv.eem.sit.bank.ikano/csp-v1?
action=searchCounterParty&authtoken=' + AuthToken)
js failed:
01: karate.webSocket('wss://api-ws-priv.eem.sit.bank.ikano/csp-v1?
action=searchCounterParty&authtoken=' + AuthToken)
org.graalvm.polyglot.PolyglotException:
io.netty.handler.codec.http.websocketx.WebSocketClientHandshakeException: Invalid handshake
response getStatus: 403 Forbidden
- com.intuit.karate.http.WebSocketClient.<init>(WebSocketClient.java:148)
- com.intuit.karate.core.ScenarioEngine.webSocket(ScenarioEngine.java:750)
- com.intuit.karate.core.ScenarioBridge.webSocket(ScenarioBridge.java:988)
- com.intuit.karate.core.ScenarioBridge.webSocket(ScenarioBridge.java:970)
- <js>.:program(Unnamed:1)
Is this something karate is not able to connect to server due to which we are getting this exception as this is working fine with postman.
Related
Trying to convert from python request to chilkat2.HttpRequest :
import requests
data = {"username": "user","password": "pass","remember": "on"}
sign_in_url = 'https://www.tradingview.com/accounts/signin/'
signin_headers = {'Referer': 'https://www.tradingview.com'}
response = requests.post(url=sign_in_url, data=data, headers=signin_headers)
token = response.json()['user']['auth_token']
P.S. Cause no right username and password - will return status_code:200
b'{"error":"Invalid username or password","code":"invalid_credentials"}'
I have this:
http = chilkat2.Http()
req = chilkat2.HttpRequest()
req.AddParam("username","user")
req.AddParam("password","pass")
req.AddParam("remember","on")
req.Path = '/accounts/signin/'
req.HttpVerb = "POST"
http.FollowRedirects = True
http.SendCookies = True
http.SaveCookies = True
http.CookieDir = "memory"
resp = http.SynchronousRequest('www.tradingview.com',443,True,req)
print(http.LastErrorText)
But response - statusCode: 403 Forbidden
What am I doing wrong?
See the tradingview.com API documentation: https://www.tradingview.com/rest-api-spec/#section/Authentication
You can see that an application/x-www-form-urlencoded POST is required.
It's easy to do with Chilkat. See this documentation showing how to send common HTTP request types: https://www.chilkatsoft.com/http_tutorial.asp
You'll want to send a request like this: https://www.chilkatsoft.com/http_post_url_encoded.asp
To make SOAP HTTPS call I write this method in jRuby.
def run host, port, path, soap_request_file,password,protocol = "HTTP"
soapMsg = ""
request = ""
soap_request_file = Expertus::TestDataFile::get_file_relative_to_script(soap_request_file)
soapMsg = IO.read(soap_request_file)
request = "POST #{path} #{protocol}/1.1\r\n"
request = request + "Content-Type: text/xml;charset=UTF-8\r\n"
request = request + "Accept-Encoding: gzip,deflate\r\n"
request = request + "Content-Type: application/soap+xml\r\n" if soapMsg.downcase.include?("soap-envelope")
request = request + "Content-Length: #{soapMsg.length}\r\n"
request = request + "Authorization: Basic #{password}\r\n"
request = request + "\r\n"
request = request + soapMsg
request = request + "\r\n"
log.debug("Trying to connect to SOAP service on #{host}:#{port}")
# Sending request
socket = TCPSocket.open(host,port)
log.debug("Sending request to SOAP service")
log.debug("#{request}")
socket.send(request, 0)
# Reading response
log.debug("Reading SOAP service response")
response = socket.read
headers,body = response.split("\r\n\r\n", 2)
log.debug("Received SOAP service response headers #{headers}")
log.debug("Received SOAP service response body #{body}")
log.debug("Closing SOAP service connection")
socket.close
log.debug("Connection with SOAP service closed")
return headers,body
end
When I make HTTP call, I get correct response back : Received SOAP service response headers HTTP/1.1 200 OK
but when I make HTTPS call, I get "Received SOAP service response headers §♥♥ ☻☻P".
Am I missing something ?
I am running the following code, in which url is http, while url1 is https.
r = requests.get(url)
data = r.json()
currstatus=pd.DataFrame(data)
r = requests.get(url1)
data1 = r.json()
tms=pd.DataFrame(data1["Response"])
My http is getting the data but I am getting the following error while trying to get data from https url.
File "C:\Users\MUJEEB UR REHMAN\Anaconda3\lib\site-
packages\requests\adapters.py", line 502, in send
raise ProxyError(e, request=request)
ProxyError: HTTPSConnectionPool(host='host name', port=443): Max retries
exceeded with url: [some credentials] (Caused by ProxyError('Cannot connect
to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection
object at 0x000002B98468AB38>: Failed to establish a new connection: [Errno
11001] getaddrinfo failed',)))
I have the following javascript app that receives data from GCDWebServer that runs on an OSX app.
var HttpClient = function() {
this.get = function(aUrl, aCallback) {
var anHttpRequest = new XMLHttpRequest();
anHttpRequest.open( "GET", aUrl, true );
anHttpRequest.onreadystatechange = function() {
if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200) {
aCallback(anHttpRequest.responseText);
document.write (anHttpRequest.responseText);
}
else {
document.write ("Not Ok: ReadyState=" + anHttpRequest.readyState + " Status= " + anHttpRequest.status);
}
}
anHttpRequest.send( null );
}
}
var client = new HttpClient();
client.get('http://xxx.xxx.x.xx:8080?var=param', function(response) {
document.write ("Success");
});
The Cocoa app runs the following code:
[webServer addDefaultHandlerForMethod:#"GET"
requestClass:[GCDWebServerRequest class]
asyncProcessBlock:^(GCDWebServerRequest* request, GCDWebServerCompletionBlock completionBlock) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
GCDWebServerDataResponse* response = [GCDWebServerDataResponse responseWithJSONObject:dict];
completionBlock(response);
});
I always get an anHttpRequest.readyState = 4 and anHttpRequest.status = 0. The anHttpRequest.responseText is empty.
However, when I open any browser and type http://xxx.xxx.x.xx:8080?var=param I get the correct results. So the server is sending the data properly.
Here is the log from GCDWebServer
[DEBUG] Did open connection on socket 13
[DEBUG] Did connect
[DEBUG] Connection received 312 bytes on socket 13
[DEBUG] Connection on socket 13 preflighting request "GET /" with 312 bytes body
[DEBUG] Connection on socket 13 processing request "GET /" with 312 bytes body
[DEBUG] Connection sent 175 bytes on socket 13
[DEBUG] Connection sent 107 bytes on socket 13
[DEBUG] Did close connection on socket 13
[VERBOSE] [xxx.xxx.x.xx:8080] xxx.xxx.x.xx:52401 200 "GET /" (312 | 282)
[DEBUG] Did disconnect
Any ideas?
Thanks in advance.
This isn't an issue with your GCDWebServer but is simply a CORS issue. If you make the same request against your server from something like curl then you will see the correct 200 HTTP status. To get the correct response from a browser you will need to have your server send the following header:
Access-Control-Allow-Origin: *
This tells the browser that it is allowed to pass back the full response it gets from your server to the JavaScript initiating the request. Without that response header the browser essentially drops all the data it received and should print out an error message in your browser's console.
I have implemented my REST Assured code like below
String tempUrl = "***/api/Document/getBrowserData";
Response rjson = given()
.param("dsId",1108)
.param("isNew", false)
.param("oToken","eed0361d314888a3f153534844869d9f")
.param("projId",837)
.param("tId",-1)
.param("type",2195)
.param("userId",104)
.post(tempUrl)
.then()
.extract()
.response();
System.out.println(rjson.asString());
and when I perform some action on the response:
System.out.println(rjson.asString()); // "Message":"No HTTP resource was found that matches
the request URI '
System.out.println(rjson.getHeaders()); // header value
System.out.println(rjson.getStatusCode()); // 404
But when I do the same thing with PostMan I am able to get a valid response.