Last time we tested our application was on Tuesday, it was working well.
Today morning a long wait and timeout received from Microsoft when sending DETECT request with binary data in body. Nothing has changed between in our application.
I tested and my keys are okay (when they are not, we receive an answer but not 200, not a timeout).
When I try to DETECT using an URL, it is working (proper content-type and body of course)
Did anyone noticed the same, or using the API differently?
HttpClient client = HttpClientBuilder.create().build();
HttpPost request = new HttpPost("https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceLandmarks=false&returnFaceId=true");
request.addHeader("Ocp-Apim-Subscription-Key", MY_KEY);
request.addHeader("Content-Type", "application/octet-stream");
HttpEntity entity = new ByteArrayEntity(Base64.getDecoder().decode(base64));
request.setEntity(entity);
response = client.execute(request);
It seems it was not a problem at out side. Suddenly it started to work...Hopefully will stay this way.
Related
I am using .NET Core Web API to make call and getting back
401, unauthorized ? I am using a REST API key.
var ApiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var _Http = new HttpClient();
var response = await _Http.GetAsync($"https://geocode.search.hereapi.com/v1/geocode?q={address},{city},{state},{postalCode},{country}&apikey={ApiKey}");
What am I missing ?
I am getting the key from the following section
UPDATE: this problem has vanished today. It appears to have been a bug on the Here side.
Yesterday: My JS API code, which has been working fine, is throwing 401s today as well, with no changes. I could kill the project and create a new one with a new API key, but I'm not sure that would fix it. I did find that it was "disabled" (due to a billing issue, I think), and I "enabled" it and it still throws 404s.
Did you confirm your email address (by clicking the link in the email they send)?
If you have not confirmed your email address, then the API Key is only valid for 30 minutes.
I am running ASP.Net 4.5, but using a very old version of the PayPal SOAP api. The reference is to paypal_base.dll with a reported version of 4.3.1.0. The code that calls the API has "using" statements that reference:
com.paypal.sdk.services
com.paypal.soap.api.
I have verified at the point where the call to the PayPal api is made, that this value
System.Net.ServicePointManager.SecurityProtocol
includes both ssl3 and tls1.2.
I am pointing at the "sandbox" mode.
But when the setExpressCheckout call is made, I get a runtime exception that says:
The request was aborted: Could not create SSL/TLS secure channel.
I have downloaded the PayPal API Samples project and using the same sandbox credentials, it works. Looking in Fiddler, the calls are nearly identical except the samples API call goes to api-3t.sandbox.paypal.com, while my code goes to api-aa.sandbox.paypal.com, but according to the documentation on TLS 1.2 readyness, both apis should work. I don't see anywhere in either API to set the endpoint other than switching between "live" and "sandbox".
In the fiddler response, both show:
"A SSLv3-compatible ServerHello handshake was found. Fiddler extracted the parameters below.
Version: 3.3 (TLS/1.2)"
And the responses are identical except for the "random" parameter. So the old API call is using TLS 1.2
My code and the Samples API code are only slightly different, the sample uses:
SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType();
populateRequestObject(request); //populate request data
SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq();
wrapper.SetExpressCheckoutRequest = request;
Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig(); //set merchant config
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper); //make the call
Where my (again, very old code looks like this):
CallerServices caller = new CallerServices();
caller.APIProfile = SetProfile.ApplicationProfile; //set merchant config
SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType();
// Create the request details object
pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
pp_request.SetExpressCheckoutRequestDetails.PaymentAction = paymentAction;
pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true;
pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType();
pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType;
pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value = paymentAmount;
pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL;
pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL;
return (SetExpressCheckoutResponseType) caller.Call("SetExpressCheckout", pp_request); //do the call
The sample code works, my code throws the SSL/TLS error. I tried upgrading to the latest SDK, but so much has changed, it will be quite a large effort to migrate all that code.
From fiddler, it seems to be using TLS 1.2 even with the old API, but I get a runtime exception about the SSL/TLS connection. Is it because of the different endpoint? Is the old API just too old?
Thanks in advance for any help - I would love to avoid migrating all that ancient code!.
EDIT: I should mention I am using the UserName/Password/Signature credentials, not certificate based credentials.
As TLS1.2 is supported in .Net4.5 but it is not a default protocol. you need to opt-in to use it. The following code will make TLS 1.2 default, make sure to execute it before making a connection to secured resource:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
I was having a similar issue, with a PP Sandbox credentialing "HttpWebRequest" in C# Web Application 4.5, receiving the following error: "You must write ContentLength bytes to the request stream before calling [Begin]GetResponse".
I read this Q/A and applied the ServicePointManager reference from above answer - as the first line in my HttpWebRequest call method, and it worked. Thanks to all.
FYI, the example code I am building is from //learn.microsoft.com, "Getting Started with ASP.NET 4.5 Web Forms and Visual Studio 2017".
Does anyone knows of a way to set or read the 'Date' HTTP header in an HTTP GET request on Windows Phone 8?
I need to be able to set the value of the Date header or at least read the value that will actually be sent in the request.
I have tried with something like:
var web_request = HttpWebRequest.CreateHttp(url);
web_request.Headers["Date"] = the_date;
But this produces an exception at run time:
System.ArgumentException: The 'Date' header must be modified using the appropriate property or method.
There's sample code here with HttpClient but this is apparently not available under Windows Phone 8:
How do you set the Content-Type header for an HttpClient request?
I have tried reading the date as well but after:
var web_request = HttpWebRequest.CreateHttp(url);
The date does not seem to be set yet.
That worked well after adding "Microsoft HTTP Client Libraries".
However there is still a problem in this library on WindowsPhone Platform.
PROBLEM:
I have a scenario where i want to add a "Date" header in a specific format, so i used
string customDate = "11/29/2013 7:46:25"
DefaultRequestHeaders.TryAddWithoutValidation("Date", customDate);
the above line adds the "Date" header, that means it does not throw any exception, but when i checked in fidler there is no "Date" header added. The same code works well in Windows8 store apps.
Looks like there is a bug in "Microsoft HTTP Client Libraries" for WindowsPhone8 platform.
By using "Microsoft HTTP Client Libraries" for Date header works well and good if Date is of DateTime object, however if i want to assign a value to Date header in a specific format as mentioned in earlier post then it does not get added.
Its a header with built-in support that you need to set/get explicitly;
web_request.Date = DateTime.UtcNow;
(Its default is 01/01/0001 00:00:00 which is not sent in the request)
The problem with:
web_request.Date
is that there is no "Date" property in the Windows Phone 8 version of HttpWebRequest.
See: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/5738e95a-5afe-4a49-929d-b51490a5480b/httpwebrequest-date-property-missing
In this link it is suggested to use HttpClient and HttpRequestMessage. Example:
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Date = DateTime.Now.Subtract(new TimeSpan(10, 0, 0));
HttpResponseMessage response = client.SendAsync(request).Result;
string resultCode = response.StatusCode.ToString();
I was stuck because HttpClient and HttpRequestMessage seem not to be available for Windows Phone 8 either. But it is possible to add them:
In Visual Studio (Express) 2012 for Windows Phone:
TOOLS -> Library Package Manager -> Manage NuGet Packages for Solution...
Then search for "Microsoft HTTP Client Libraries" and install it.
After that System.Net.Http is available and the HttpClient solution can be used.
I've noticed recently, that my code, that uses AFNetworking (latest version from master branch) stopped working properly under iOS 6.
Here's my code:
httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:baseURL]];
httpClient.operationQueue.maxConcurrentOperationCount = 1;
where httpClient is a class variable.
Next, I'm creating a request:
NSMutableURLRequest *signInRequest = [httpClient requestWithMethod:#"POST" path:#"/user/register" parameters:dataToSend];
signInRequest.timeoutInterval = 15.0;
signInRequest.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
AFJSONRequestOperation *signInOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:signInRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
// Blah
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
// Blah
}];
[httpClient enqueueHTTPRequestOperation:signInOperation];
All the other requests are constructed similarly. The first enqueued operation works well, I can get into success handler block. However, next calls to other requests are finished with fail handler and request timeout error, no matter how big is timeout value I choose.
I have done the same calls using plain NSURLConnection, writing a tons of code :), with success, requests were processed properly.
I switched to iOS 5 device, and the code above works fine.
I switched to 3G connection (iOS 6), and the code above works.
It seems like I have this problem only on WiFi connections (except the case when I'm in the same subnet with my REST server.)
Any thoughts on this?
Thank you in advance.
It seems you also posted an issue on AFNetworking's github and found the solution yourself :)!
It seems like iOS 6 changes something to TCP implementation or something. I moved server to third-party hosting and it is working now.
For future readers, the issue can be found here.
I have an Android application with an ASP.NET backend. I have the registration_id for the phone as well as an auth token from google for the application server that is performing a push.
When I make the http post request to C2DM so that the phone gets a message I keep getting the 401 Unauthorized. Here is how I'm making the request in .NET:
WebRequest myRequest = WebRequest.Create("https://android.apis.google.com/c2dm/send");
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Method = "POST";
myRequest.Headers.Add("Authorization", "GoogleLogin auth=" + authId);
// buiold the post string
StringBuilder myPost = new StringBuilder();
myPost.AppendFormat("registration_id={0}", regId);
myPost.AppendFormat("&data.payload={0}", msg);
myPost.AppendFormat("&collapse_key={0}", colKey);
// write the post-string as a byte array
byte[] myData = ASCIIEncoding.ASCII.GetBytes(myPost.ToString());
myRequest.ContentLength = myData.Length;
Stream myStream = myRequest.GetRequestStream();
myStream.Write(myData, 0, myData.Length);
myStream.Close();
// Do the actual request and read the response stream
WebResponse myResponse = myRequest.GetResponse();
Stream myResponseStream = myResponse.GetResponseStream();
StreamReader myResponseReader = new StreamReader(myResponseStream);
string strResponse = myResponseReader.ReadToEnd();
myResponseReader.Close();
myResponseStream.Close();
Any help would be much appreciated.
Advice corner: Have some confidence in your code every once and a while! And, even Google messes up sometimes.
After spending about nine hours reading every blog post and article about Google OAuth and C2DM and trying different things in my code, I emailed Google. I'm excited to say that not only did I receive a response very quickly, but also that my account was messed up. Something went wrong while I was registering on their site and although it appeared that everything was working from the registration success email I received, it wasn't. I re-registered and everything works!
I have encountered a similar problem: error 401 "Unauthorized" while trying a google c2dm (cloud to device messaging) code sample. It looks like the example used to work as is, but now Google has changed its conditions. Before running code examples, you have to sign-up:
http://code.google.com/android/c2dm/signup.html
I signed up, and the stuff began to work in minutes.
I've got the same problem, i.e. suddenly my C2DM_ACCOUNT_EMAIL stopped working.
To solve the problem, just fill the registration again with same info and the same C2DM_ACCOUNT_EMAIL.
HTH