windows phone, change hour phone httpclient web api 404 error - windows-phone-8.1

I have a windows phone app, that tries a log in to a web api with a HttpClient call.
If the hour of the phone is correct:
DateTime.Now == "19/02/2015";
then the HttpClient returns a OK status code.
But if the hour of the phone is incorrect (past)
DateTime.Now == "19/02/2010";
then the HttpClient returns a 404 error, why is this, and how can I solve it?

Related

selenium-chromedriver: Is it possible to access everything in the browser Inspector-Network page?

In Chrome, in F12-Network there are lots of network requests, for example for stackoverflow homepage there are:
- stackoverflow.com
- jquery.min.js
- stub.en.js?v=xxxxxxxxx
- stacks.css?v=xxxxxxxxx
- ...
Is it possible to get these requests?
It's not clear from question, but I guess you were to access all these requests via Selenium API. Yes, it became possible with Selenium 4.
Sample below shows catching requests on the google page
ChromeDriver driver = new ChromeDriver(); // driver should be of type ChromeDriver
DevTools chromeDevTools = driver.getDevTools();
chromeDevTools.createSession();
chromeDevTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
chromeDevTools.addListener(Network.requestWillBeSent(),
req -> {
System.out.println(String.format("Sent %s request to %s",
req.getRequest().getMethod(),
req.getRequest().getUrl()
));
});
driver.get("https://www.google.com");
chromeDevTools.send(Network.disable());
driver.close();

C# WebRequest to a URL that is configured for Windows Authentication

I am trying to get user photos out of Microsoft Exchange using the GetUserPhoto REST request documented here: https://msdn.microsoft.com/en-us/library/office/jj190905%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396
My problem is no matter what I do the connection gets closed automatically and it can't authenticate using NTLM. Microsoft even provides code but when you run this in a IIS web application even if it is using an application pool running as a domain user, it never can authenticate.
This is my current code that isn't working:
request = System.Net.WebRequest.Create($"https://{Settings.ExchangeServer}/ews/exchange.asmx/s/GetUserPhoto?email={primarySmtpAddress}&size=HR240x240") as System.Net.HttpWebRequest;
request.ServerCertificateValidationCallback = delegate { return true; };
request.UseDefaultCredentials = true;
resp = request.GetResponse() as System.Net.HttpWebResponse;
Now I can put this in a console application and run it and then it works. But in IIS it just won't work at all. I've even tried RestSharp with no luck.
Sounds like a delegation issue eg the credentials your impersonating can only be used to access resources local to the IIS server they are being impersonated on. For you to access Exchange you need to have delegation configured correctly see https://blogs.msdn.microsoft.com/emeamsgdev/2012/11/05/ews-from-a-web-application-using-windows-authentication-and-impersonation/
The problem was it wasn't trying to connect with TLS 1.2. Once it clicked in my head, the error message was saying the connection closed and not actually returning a 401. I user ServiceManager to set it to TLS1.2 and then it started working.
Glen Scales help point me in the right direction though to troubleshoot it further.

Windows push notification service using Pushsharp giving Notification Failure

var push = new PushBroker();
push.OnNotificationSent += NotificationSent;
push.OnChannelException += ChannelException;
push.OnServiceException += ServiceException;
push.OnNotificationFailed += NotificationFailed;
push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
push.OnChannelCreated += ChannelCreated;
push.OnChannelDestroyed += ChannelDestroyed;
push.RegisterWindowsPhoneService();
push.QueueNotification(new WindowsPhoneToastNotification()
.ForEndpointUri(new Uri(uri))
.ForOSVersion(WindowsPhoneDeviceOSVersion.Eight)
.WithBatchingInterval(BatchingInterval.Immediate)
.WithNavigatePath("/LandingView.xaml")
.WithText1("PushSharp")
.WithText2("This is a Toast"));
push.StopAllServices();
I am using pushsharp nuget package for push notifications and while passing uri to this c# backend code for windows, I am getting notification failure exception.
I am using the latest version of PushSharp (version 3.0) in a project of mine to send toast notifications to Windows Phone Devices and it is working fine for me. I notice by the code you have above that you are using an older version of the PushSharp package, there is a new 3.0 version available from nuget.
You could use that latest package to send toast notification to windows phone devices. The latest version of PushSharp uses the WNS as opposed to the old MPNS.
If you go to that nuget get link i supplied above and download the solution you can see some examples on how to implement the push notifcations for windows phone using WNS. Look under the PushSharp.Test project (look for the WNSRealTest.cs file).
Below is an example of how you can send a toast notification to windows phone device:
var config = new WnsConfiguration(
"Your-WnsPackageNameProperty",
"Your-WnsPackageSid",
"Your-WnsClientSecret"
);
var broker = new WnsServiceBroker(config);
broker.OnNotificationFailed += (notification, exception) =>
{
//you could do something here
};
broker.OnNotificationSucceeded += (notification) =>
{
//you could do something here
};
broker.Start();
broker.QueueNotification(new WnsToastNotification
{
ChannelUri = "Your device Channel URI",
Payload = XElement.Parse(string.Format(#"
<toast>
<visual>
<binding template=""ToastText02"">
<text id=""1"">{0}</text>
<text id=""2"">{1}</text>
</binding>
</visual>
</toast>
","Your Header","Your Toast Message"))
});
broker.Stop();
As you may notice above the WnsConfiguration constructor requires a Package Name, Package SID, and a Client Secrete. To get these values your app must be registered with the Store Dashboard. This will provide you with credentials for your app that your cloud service will use in authenticating with WNS. You can check steps 1-3 on the following MSDN page for details on how to get this done. (note in the link above it states that you have to edit your appManifest.xml file with the identity of your app, I did not do this step, just make sure you have your windows phone app setup correctly to receive toast notification, this blog post will help with that.
Hope this helps.

If Modified Since HttpWebRequest windows phone 8

I have to download a file from an http server only if the date is changed
if i insert in a request
request = HttpWebRequest.CreateHttp("http://myserver.....");
request.Headers["If-Modified-Since"] = previousValue;
receive errors
in a Windows phone 8 it is possible?
Thank you

HttpClient Portable returns 404 notfound on WP8

I'm porting a W8 application that uses httpclient library to connect to our server.
The main purpose of the application is to send images, but when I try to send pictures on my WP8 I got a 404 not found error (seems that Microsoft remapped to 404 a lot of errors), if i check the server logs, I can see that the server recevied about 1/4 of the image before failling. The same function seems to works fine in my W8 application (didn't tested on 3G), and works on WP8 if I use Wifi connection. I think that the problem could be the waiting time, so I tried to add Keep-Alive headers without success.
The current code I have is:
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = TimeSpan.FromMinutes(10);
Stream streamW = new MemoryStream();
this.bSyncOK = await Send(streamW);
streamW.Seek(0, SeekOrigin.Begin);
HttpResponseMessage response = await httpClient.PostAsync(sUri, new StreamContent(streamW));
if (response.IsSuccessStatusCode)
{
Stream streamR = await response.Content.ReadAsStreamAsync();
this.bSyncOK = await Recv(streamR);
streamR.Dispose();
}
else
throw new HostNotFoundException();
}
The same server is used to upload pictures on other platforms like IOS and Android without problems.
I reproduced the problem using fiddler to simulate modem speeds. The problem is happening because Phone's HTTPWebRequest implementation will timeout the request whenever it exceeds around 60s. In the debugger I see them getting back ERROR_INTERNET_TIMEOUT from their native layer. The only workaround I can think of at the moment would be to send the file in smaller POSTs, assuming the server supports that.