Below is my specifications I am running:
Operating System Name = Mac OS X Version
= 10.9.5 Architecture = 64bit
Titanium CLI CLI Version = 3.4.1 Titanium SDK SDK
Version = 3.5.0.GA Target Platform =
android
Ex:-> Node.js Node.js Version = 0.10.24 npm Version
= 1.3.21
Here is my code:
var url = "http://192.168.1.100/test.php";
var xhr = Titanium.Network.createHTTPClient();
xhr.onerror = function(e) {
swim.lib.err('' + e.error);
alert('HTTP ERR...');
};
xhr.onload = function(e) {
Ti.API.info(this.responseText);
alert('success');
};
xhr.open("POST", url);
//post/get and your URL
xhr.setRequestHeader("content-type", "application/json");
var param = {
"user" : {
"email" : "someone#email.com",
"password" : "secure"
}
};
xhr.send(JSON.stringify(param));
What does your server expect? I just tested your code replacing the url with http://requestb.in/157oi2x1 and that seems fine, as you can see on http://requestb.in/157oi2x1?inspect:
Headers
Via: 1.1 vegur
Connect-Time: 1
User-Agent: Appcelerator Titanium/3.5.0 (iPhone Simulator/8.2; iPhone OS; en_US;)
Host: requestb.in
Total-Route-Time: 0
X-Requested-With: XMLHttpRequest
Content-Type: application/json
Accept-Language: en-us
X-Titanium-Id: d6caf6df-6a27-49b0-ad38-1c0d64356393
X-Request-Id: 257ddc46-066d-4c1d-95d6-cf6a642dbeab
Content-Length: 58
Accept: */*
Connection: close
Accept-Encoding: gzip, deflate
Body
{"user":{"email":"someone#email.com","password":"secure"}}
Related
I have a netcoreapp2.1 webapp which is presenting an issue in Google Chrome, but not Edge or IE, during the OIDC flow redirect. It simply stops at http://localhost:5000/signin-oidc with this response received:
General:
Request URL: http://localhost:5000/signin-oidc
Request Method: POST
Status Code: 500 Internal Server Error
Remote Address: [::1]:5000
Referrer Policy: no-referrer-when-downgrade
Response Headers:
Content-Length: 0
Date: Tue, 04 Aug 2020 09:49:32 GMT
Server: Kestrel
Request Headers:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en;q=0.9
Cache-Control: max-age=0
Connection: keep-alive
Content-Length: 2148
Content-Type: application/x-www-form-urlencoded
Host: localhost:5000
Origin: null
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: cross-site
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
Form Data:
code: Ry9Pec...rdG1U0SB
scopes: resource.WRITE+openid+resource.READ
state: CfDJ8JZ...oESbUvQ
id_token: eyJhbG...9sXMEhs
When I visit localhost:5000 in chrome (incognito or not) the code never reaches the OnTicketReceived event, whereas when fired from IE, Edge etc it does, and proceeds just fine.
This is the startup class:
public class Startup
{
private AppSettings _appSettings;
private IConfiguration _config;
public Startup(IConfiguration configuration)
{
_config = configuration;
_appSettings = _config.Get<AppSettings>();
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.Configure<AppSettings>(_config);
services.AddSingleton<IAPIRepository, APIRepository>();
services.AddSingleton<IUserRepository, UserRepository>();
services.AddSingleton<INavigationRepository, NavigationRepository>();
services.UseOpenIDConnectMiddleware(new OpenIDConnectMiddlewareOptions
{
BaseUrl = _appSettings.API.BaseUrl,
AppName = _appSettings.AppName,
ClientId = _appSettings.API.ClientId,
ClientSecret = _appSettings.API.ClientSecret,
Secure = !_appSettings.Local
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseAuthentication();
if (!_appSettings.Local)
{
app.UseGlobalLoginMiddleware();
}
if (_appSettings.FeatureFlags["ProcessRedirectionRules"])
{
app.UseRedirectUserMiddleware(_appSettings.RedirectionRules);
}
app.UseMvc();
app.UseProtectHTMLRouteMiddleware();
if (_appSettings.Local)
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
ProjectPath = Path.Join(Directory.GetCurrentDirectory(), "../UI"),
ConfigFile = "node_modules/#vue/cli-service/webpack.config.js",
HotModuleReplacement = true
});
}
else
{
app.UseDefaultFiles();
app.UseStaticFiles();
}
app.UseJavascriptVarMiddleware(new JavascriptSettingsMiddlewareOptions
{
FileName = "env.js",
ObjectName = "__env",
Settings = new Dictionary<string, string>
{
{ "insightsKey", _appSettings.ApplicationInsights.InstrumentationKey },
{ "environment", _appSettings.Environment },
{ "gatekeeperBaseUrl", _appSettings.Gatekeeper.BaseUrl }
}
});
app.UseGlobalSignoutMiddleware(new GlobalSignoutMiddlewareOptions
{
GatekeeperLogoutUrl = _appSettings.API.LogoutUrl
});
app.UseHTMLRouteFallback(new HTMLRouteFallbackMiddlewareOptions
{
Local = _appSettings.Local,
Path = Path.Join(Directory.GetCurrentDirectory(), "../UI/dist")
});
}
}
I have cleaned the localhost and localhost:5000 cookies from the browser.
A quick guess would be that it is a SameSite cookie issue that different browsers handle differently due to various bugs.
This article might give you a starting point:
How To Prepare Your IdentityServer For Chrome's SameSite Cookie Changes - And How To Deal With Safari, Nevertheless
Also, your Configure method looks very odd. Because the ordering of the App.Use statements matter and usually you would put the app.UseMvc(); last in that method. Each incoming request will pass through those middlewares that the App.UseXXX adds and if the ordering is not correct then you will have issues.
I’ve been battling this problem now for a few hours, and have tried several solutions (including using dataset, datareader to access the data, converting the datareader/dataset into a list of objects and then sending the result as a Json. I’ve also tried using Json.Net and a replacing the $http with an AJAX call, all to no avail.
In an MVC4 project, I’ve detailed an angular controller to retrieve data from our ACCESS database. An $http request is sent to the (local)server, received, and executed. The results generated, however, are not received back by the angular controller.
Any and all help will be greatly appreciated
This is the method:
[HttpPost]
public JsonResult GetCatalogueItems(string get)
{
JsonResult toReturn = null;
string cs = ConfigurationManager.ConnectionStrings["connStringPT"].ConnectionString;
OleDbConnection cn = new OleDbConnection(cs);
string queryStart = " SELECT catNum, testName, price, comments FROM table_catalog WHERE ";
DataSet ds = new DataSet();
try
{
List<ptProductModel> listToReturn = new List<ptProductModel>();
string query = queryStart + get + "=true;";
cn.Open();
OleDbCommand cmd = new OleDbCommand(query, cn);
OleDbDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
ptProductModel item = new ptProductModel
{
Number = reader[0].ToString(),
Name = reader[1].ToString(),
//comment = reader.GetString(reader.GetOrdinal("comments")) !=null ? reader.GetString(reader.GetOrdinal("comments")) : null,
price = reader[2].ToString()
};
listToReturn.Add(item);
}
reader.Close();
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
toReturn = Json(listToReturn.Select(s => new { Name = s.Name, price = s.price, Number = s.Number }), JsonRequestBehavior.AllowGet);
}
}
catch (OleDbException ex)
{
toReturn = Json("Error", JsonRequestBehavior.AllowGet);
}
return toReturn;
}
}
And this is the angular controller:
myApp.controller('ptCatalogueController', ['$scope', '$http', function ($scope, $http) {
$scope.catalogueItems = [];
$scope.Product = "";
$scope.Init = function () { }
$scope.GetProducts = function (productSet) {
console.error(productSet, 'blabla');
$http.post({
url: '/Catalogue/GetCatalogueItems', data: { get: productSet }
}).then(
// success callback
function (data) {
$scope.catalogueItems = data;
console.log($scope.catalogueItems);
console.debug("success");
}
,
//error callback
function (response) {
console.log(response);
console.debug("error");
}
)}
}]);
and the header:
POST /Catalogue/[object%20Object] HTTP/1.1
Host: localhost:49078
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,he;q=0.6
Cookie: ASP.NET_SessionId=fvfswezab5g1ekyiuotmpw3m
Origin: http://localhost:49078
Referer: http://localhost:49078/Catalogue/Index
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
X-DevTools-Emulate-Network-Conditions-Client-Id: 0689EBCB-E24D-48E3-ACF9-0D94BB0B6F16
HTTP/1.1 404 Not Found
Cache-Control: private
Content-Length: 3732
Content-Type: text/html; charset=utf-8
Date: Sun, 22 Nov 2015 07:59:03 GMT
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-SourceFiles: =?UTF-8?B? RTpcR2VuZXJhbCBGb2xkZXJcRGV2ZWxvcG1lbnRcV2ViLVBzeWNoVGVjaC1OZXdTaXRlXFdlYi1Qc3ljaFRlY2gtTmV3U2l0ZVxDYXRhbG9ndWVcW29iamVjdCBPYmplY3Rd?=
I have got problem with using HttpClient in Windows Phone 8.1 application. I'm new in this WP 8.1 class.
I write this code:
var uri = new Uri("http://testapiurl.com");
var message = new
{
Name = "Test",
Surname = "Test",
Mail = "test#test.pl",
Password = "test1234"
};
var json_object = JsonConvert.SerializeObject(message);
HttpStringContent stringContent = new HttpStringContent(json_object.ToString(), UnicodeEncoding.Utf8, "application/json");
var httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.PostAsync(
uri,
stringContent);
Debug.WriteLine(response);
After compilation and running I got message
StatusCode: 200, ReasonPhrase: 'OK', Version: 2, Content: Windows.Web.Http.HttpStreamContent, Headers:
{
Connection: Keep-Alive
Server: Apache/2.4
Transfer-Encoding: chunked
Keep-Alive: timeout=10, max=100000
Date: Mon, 17 Aug 2015 04:59:02 GMT
X-Powered-By: PHP/5.4.39
}{
Content-Type: application/json; charset=UTF-8
}
In API help and examples I have information that in return it should be Status Code: 200 and name of created user. But I don't get it. Second thing is that when I push the second time the same code to create account I get back the same response. In help for API it should be error 409 conflict the same account already exist.
I don't know that this code is good, or am I missing big amount of code.
You need to use
var responseString = await response.Content.ReadAsStringAsync();
to get your response string. There will be everything from the actual response.
Your current code only writes the response headers and the content type.
I have an Web Api controller for access data from server:
public class ServicesController : ApiController
{
[AcceptVerbs("POST")]
public IList<TreeMenuItem> LoadMetadata()
{
List<TreeMenuItem> itemsMenu = new List<TreeMenuItem>();
TreeMenuItem dataSource = new TreeMenuItem("1", "DataSources", null);
itemsMenu.Add(dataSource);
return itemsMenu;
}
}
which is call by an angularJS controler:
angular.module('App').
controller('TreeMenuController', ["$scope", "$http", treeMenuController]);
function treeMenuController($scope, $http) {
var baseUrl = "api/Services/LoadMetadata";
$http.post(baseUrl)
.then(function (result) {
$scope.roleList = result.data;
});
};
In browser network I have:
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate
Content-Length:2
Content-Type:application/json;charset=UTF-8
Request Payload
{}
Response Headers:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 4
in Response tab: [{}].
What is wrong?
I make it work:
The big help was the response message when I put in browser the address for accessing api services (api/Services/LoadMetadata):
The error answer was in an xml file where I found that was problem with serialization of the object TreeMenuItem. The advice was to decorate with DataContract the class and DataMember the class properties - like in WCF. After I did that (was need to add reference in project to System.Runtime.Serialization), everything was perfect.
It takes nearly 50 seconds to load a big chunk of 35 MB Json when accessing the Api. So to improve performance I added the WebApiContrib.Formatting.ProtoBuf to my project. The data is displayed in a Kendo UI Grid.
What am I missing here? A dataType or type in the View, or anything like that? And are there other or better ways to improve the performance?
Here some snippets->
POCO-Class:
[ProtoContract]
public partial class KDAuftraege
{
[ProtoMember(1)]
public int AngebotsNummer { get; set; }
[ProtoMember(2)]
public Nullable<int> BesuchsNummer { get; set; }
[ProtoMember(3)]
public Nullable<int> Kennummer { get; set; }
[ProtoMember(4)]
View:
var remoteDataSource = new kendo.data.DataSource({
transport: {
read: {
url: '/api/WebApiAuftraege'
},
},
Controller:
public IQueryable<KDAuftraege> GetKDAuftraeges()
{
//return db.KDAuftraeges.Take(500);
return db.KDAuftraeges;
}
WebApi:
config.Formatters.Add(new ProtoBufFormatter());
Headers:
Cache-Control no-cache
Content-Length 36227588
Content-Type application/json; charset=utf-8
Date Sat, 07 Jun 2014 09:23:54 GMT
Expires -1
Pragma no-cache
Server Microsoft-IIS/8.0
X-AspNet-Version 4.0.30319
X-Powered-By ASP.NET
X-SourceFiles =?UTF-8?B?YzpcdXNlcnNcb2xkc3BvcnRcZG9jdW1lbnRzXHZpc3VhbCBzdHVkaW8gMjAxM1xQcm9qZWN0c1xWaXM0XFZpczRcYXBpXFdlYkFwaUF1ZnRyYWVnZQ==?=
Anfrage-HeaderQuelltext anzeigen
Accept */*
Accept-Encoding gzip, deflate
Accept-Language de,en-US;q=0.7,en;q=0.3
Connection keep-alive
Cookie __RequestVerificationToken=wMVQWPOkXsB2XDIFN_07RJDtKqN_90dLRYaBYJGsFSGEHTcQ1S6e15mPiWrvkMHS8HrAlHYAI0OVSkqtPQHFVMP5DxoyccijSktL_KsoEFU1; .AspNet.ApplicationCookie=RTQ61CfArDWHlWN06eOpZiZY6NmFGp0SwCCuR8bQCtnItSz6S8YTasQu4-uoRQCc-XqWDCZmtOpEb-b0SyIioQPomkm1BrKywMcVwt3bF_JBxORKGg-UNSHyPvFyBohiS1sJ354LpRHIjrPIA8rUexvZih4VrK9lvHu_sm21ncNXXV7jATKAjTdX7J3XvfxRsF11fhgDNtpXPEWxQPjD7Rkj5yvdqI-vbfr9tfQbszUR1O3oOjYcRxUvvVrJ7xnt-caxt-o_Kut1dixLEA241pMGPCHfetWK73Yp148K3X9By6ylHFOTEjjDwHZyHLIrBwwOZ-ujnaOf20jQzeZXaF16bHxeadLYuKK-Z2DpdzaJXPzZd2pBbzHJMFX7USfZmp7OZzLpOitLCMovGHwdRiLD0F2NR1a0iTHCgiZLvA8
Host localhost:19275
Referer http://localhost:19275/MvcAuftraege
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
X-Requested-With XMLHttpRequest
Options 1: Change your view DataSource code (I think this is right)
var remoteDataSource = new kendo.data.DataSource({
transport: {
read: {
type: 'GET',
headers: { Accept: 'application/x-protobuf' },
url: '/api/WebApiAuftraege'
},
},
Option 2: Change your Web API Formatters so that ProtoBuf is the default:
config.Formatters.Insert(0, new ProtoBufFormatter());