IServerXMLHTTPRequest on HTTPS - ssl-certificate

I am trying to implement a c++ application that will access an HTTPS server using IServerXMLHTTPRequest.
My current code is:
CComPtr<MSXML2::IServerXMLHTTPRequest> xmlHttp;
HRESULT hr = xmlHttp.CoCreateInstance(__uuidof(ServerXMLHTTP));
hr = xmlHttp->open(_T("POST"),_T("https://someurl.com/somepath"),false);
hr = xmlHttp->setTimeouts( 100000,
50000,
100000,
100000
);
hr = xmlHttp->setOption(SXH_OPTION_SELECT_CLIENT_SSL_CERT,
xmlHttp->getOption(SXH_OPTION_SELECT_CLIENT_SSL_CERT));
hr = xmlHttp->setRequestHeader(_T("Content-Type"),_T("application/x-www-form-urlencoded"));
sPostData = ...;
hr = xmlHttp->send((BSTR)sPostData);
When I try to run the above code, the server returns an 403 (Forbidden) error.
What could be the cause of this? And, what should I do about this?

I got it working!
For those who might encounter this same problem in the future, you can solve this by specifying in the URL the actual file name and extension instead of just specifying the path.
You can refer to this link: 403 ERROR
Thank you!

Related

ggmap error: HTTP 400 Bad Request The Google Maps Platform server rejected your request. The provided API key is invalid

I am trying to retrieve a ggmap background map using get_map() in R but I keep getting an error message "HTTP 400 Bad Request The Google Maps Platform server rejected your request. The provided API key is invalid.".
Examples:
BA <- get_map("Buenos Aires, Argentina", source = "stamen", maptype = "toner-lite", zoom = 11)
spainmap<- ggmap(get_googlemap(center = c(lon = -3.703790, lat = 40.416775), zoom = 10, maptype = 'terrain', color = 'color'))
I know that every user must have a valid google API key, I´ve created a billing account and my key is definitely valid. I´ve also enabled all the APIs, including Geocoding, Geolocation, Maps Embed and Maps Static since others suggested this.
I´ve reinstalled the latest version of R and Rstudio, restarted R session multiple times but nothing seems to work.
According to this website https://developers.google.com/maps/documentation/maps-static/error-messages I´m getting the error because some required parameter is either missing or is invalid, but I really don´t think that´s the case since I´ve tried to get maps in different locations and using various ggmap functions but nothing works.
How do I fix this? Has anyone else had this problem?

I am receiving a versioning date error when trying to call the FourSquare API

I am getting an error when trying to call on the Foursquare places API about my versioning being old, however the date specified in the error is much older than the date I am using. Am I missing something?
This is for a certification project, can someone please advise what's going on, I have not found any resources on this. I have tried versioning dates 20180604 and 20180323 and get the same error. I have attached my code.
CLIENT_ID = 'xxxxxx'
CLIENT_SECRET = 'xxxxx'
VERSION = '20180604'
LIMIT = 30
Latitude = 38.925496298
Longitude = -77.0350515265
And this is the error when I try and call results
results = requests.get(url).json()
ERROR: 'meta': {'code': 410,
'errorType': 'param_error',
'errorDetail': 'The Foursquare API no longer supports requests that pass in a version v <= 20120609. For more details see https://developer.foursquare.com/overview/versioning',
'requestId': '5f4e58420179823aae7b5f91'},
'response': {}}
It works now. I am not sure why it wasn't before (the only thing I did differently was install Folium) but in any event it is now working. Sorry I can't offer more clarity around this. If others are having similar issues, I would try using a different environment. I was operating in IBM Watson Studio and switched to my local instance of Jupyter, confirmed it worked, then it worked when I went back to Watson. So I'm not sure, but that's what I can offer.

Get User Location Information using EKTRON API

I have an ektron application and I am using the following code to get user location information,
try
{
string IP = HttpContext.Current.Request["remote_addr"];
if (!string.IsNullOrEmpty(HttpContext.Current.Request["ip"]))
IP = HttpContext.Current.Request["ip"];
else
IP="my system ip";
//var userData = Ektron.Cms.UserContext.GetLocationInfo(IP);
//var userData = Ektron.Cms.UserContext.GetLocationInfo("my system ip");
//Ektron.Cms.UserLocationData userData = Ektron.Cms.UserContext.GetCurrentUserLocationInfo();
//var userData = Ektron.Cms.UserContext.GetLocationInfo(IP);
visitorCountry = userData.CountryCode;
}
In the above code I have tried 4 different methods (these are commented by //) to get userData. But I am getting null value in all these 4 attempts that's why I'm getting exception in userData.CountryCode;
How can I resolve this?
In IP I am getting value as ::1 and Ektron.Cms.UserContext.IP is also giving value ::1
I am using ektron 8.7
I don't have v8.7 running right now, but I do have v9, and here's what I found:
I ran the following code:
var location = Ektron.Cms.UserContext.GetLocationInfo("74.125.225.113");
Response.Write("<pre>" + Ektron.Cms.UserContext.IP + "</pre>");
Response.Write("<pre>" + string.Format("{0}, {1} ({2} / {3})", location.City, location.Region, location.Longitude, location.Latitude) + "</pre>");
Here's what was displayed on the screen:
::1
Mountain View, CA (-122.057403564453 / 37.4192047119141)
I'm running the site locally on my dev machine, so I'm browsing to http://localhost/test.aspx - no real surprise that Ektron.Cms.UserContext.IP is returning "::1" for me. I didn't have access to a server, so I pinged www.google.com and got an IP address of 74.125.225.113. Using that IP address, Ektron gave me a non-null response.
I thought I had v8.61 installed as well, but when I ran the same code in that environment, I got the following error: System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
I'll try to clean up my v8.6 install and see if the code works there as well, but in the meantime, I'd try using some known IP addresses and see if you get better results.

Problems Connecting to MtGox API 2 with Python

I am writing a trading program that I need to connect to MtGox (a bitcoin exchange) through the API v2. But I keep getting the following error:
URL: 1 https://data.mtgox.com/api/2/BTCUSD/money/bitcoin/address
HTTP Error 403: Forbidden.
Most of my script is a direct copy from here (that is a pastebin link). I just had to change it to work with Python 3.3.
I suspect that it has to do with the part of script where I use base64.b64encode. In my code, I have to encode my strings to utf-8 to use base64.b64encode:
url = self.__url_parts + '2/' + path
api2postdatatohash = (path + chr(0) + post_data).encode('utf-8') #new way to hash for API 2, includes path + NUL
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()).encode('utf-8'))
# Create header for auth-requiring operations
header = {
"User-Agent": 'Arbitrater',
"Rest-Key": self.key,
"Rest-Sign": ahmac
}
However, with the other guy's script, he doesn't have too:
url = self.__url_parts + '2/' + path
api2postdatatohash = path + chr(0) + post_data #new way to hash for API 2, includes path + NUL
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()))
# Create header for auth-requiring operations
header = {
"User-Agent": 'genBTC-bot',
"Rest-Key": self.key,
"Rest-Sign": ahmac
}
I'm wondering if that extra encoding is causing my header credentials to be incorrect. I think this is another Python 2 v. Python 3 problem. I don't know how the other guy got away without changing to utf-8, because the script won't run if you try to pass a string to b64encode or hmac. Do you guys see any problems with what I am doing? Is out code equivalent?
This line specifically seems to be the problem -
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()).encode('utf-8'))
To clarify, hmac.new() creates an object to which you then call digest(). Digest returns a bytes object such as
b.digest()
b'\x92b\x129\xdf\t\xbaPPZ\x00.\x96\xf8%\xaa'
Now, when you call str on this, it turns to
b'\\x92b\\x129\\xdf\\t\\xbaPPZ\\x00.\\x96\\xf8%\\xaa'
So, see what happens there? The byte indicator is now part of the string itself, which you then call encode() on.
str(b.digest()).encode("utf-8")
b"b'\\x92b\\x129\\xdf\\t\\xbaPPZ\\x00.\\x96\\xf8%\\xaa'"
To fix this, as turning bytes into a string back into bytes was unnecessary anyhow(besides problematic), I believe this will work -
ahmac = base64.b64encode(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest())
I believe you are likely to find help in a related question of mine although it deals with the WebSocket API:
Authenticated call to MtGox WebSocket API in Python 3
Also, the HTTP 403 error seems to indicate that there is something fundamentally wrong with the request. Even if you threw the wrong authentication info at the API you should have gotten an error message as a response and not a 403. My best guess is that you are using the wrong HTTP method so check if you are using the appropriate one (GET/POST).

400 error message when trying to create a new document in CouchDb using XMLHttpRequest

I am trying to create a new document in a couchDB database but with the following code I get a '400 bad request' response. I want to create a document that does not contain any other information than the _id (and of course the generated _rev).
var xhrCreate = new XMLHttpRequest();
xhrCreate.open('PUT','http://domainName:5984/dbName/docName/', true);
xhrCreate.setRequestHeader("Content-type", "application/json");
xhrCreate.send();
The CouchDb documentation says that a 400 error indicates a:
"Bad request structure. The error can indicate an error with the request URL, path or headers. Differences in the supplied MD5 hash and content also trigger this error, as this may indicate message corruption."
Could anyone point me in the right direction? Hints and help is much appreciated.
CouchDB requires an empty document as part of the content:
xhrCreate.send('{}');