Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Enable Windows 8 App(HTML) to make XHR Request to Service Hosted in Different Domain

, 25 Jul 2014
Rate this:
Please Sign up or sign in to vote.
Enable Windows 8 App(HTML) to make XHR Request to Service Hosted in Different Domain

Introduction

In this small article, we are going to learn how to enable our Windows 8 app to make an XHR request to service hosted in different domain (e.g Web API hosted in some virtual machine and app is running in my local machine). It seems simple and yes the solution is also simple and straight forward, since I'm new to Win8 app development it took time to understand the things. Let's define the problem.

Problem

The first thing is that I have two solutions; one is Win8 JavaScript app solution and another one is service solution. I have used Web API for it. Now, when I host my service in local IIS and access the service from my Win8 app, it was working, i.e., I was able to get the data and response status was 200. But when I hosted the same service in some virtual machine(VM) and tried to access it was giving 404(Not found) error. SO what's the solution???

Solution

The following is my XHR request:
WinJS.xhr({
 type: "POST",
 url: "url"
 data: JSON.stringify(some_data),
 headers: {"Content-type": "application/json; charset=utf-8" },
 }).then(
 function (success) {
 // play with the data
 },
 function (error) {
 //handle the errors
 }
 );

There is nothing wrong with the request nor with the service, but the thing is we have to enable capabilities of Win8 app in package.appxmanifest. In this file, under Capabilities tab, you can find Capabilities section in that check the Private Networks (Client & Server) check box and save it, this solves the problem.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Murali Gowda
Software Developer (Senior)
India India
Yet to be written
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 25 Jul 2014
Article Copyright 2014 by Murali Gowda
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid