w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
How to configure nginx rules so that if one failed it serve the request using another
http://wiki.nginx.org/HttpCoreModule#try_files try_files is your friend, here you can do the order you want to try files and finaly have the proxypass upstream.

Categories : Nginx

How to change Content-Type of GET-Request via firefox addon RESTClient
I think you have to specify the Accept header with the media type you want in addition to the Content-Type header that states what is the content type of your request, NOT the content type of the response which indeed is set by the Accept header So use the Accept header instead of Content-Type header

Categories : Rest

How to unmarshall incoming request payload as method/function arguments based on content type in Python flask or bottle frameworks
There are some caveats in doing so for code readability but a possible solution is as follow. Define the serialization method. If you need to work with different clients I suggest JSON. Create a decorator and put it between your function and the route @route(...) @expandargs def foo(id, bar, baz): ... In the decorator use request.json() (automatically decodes the payload if it's JSON) to expand the args and then you'll call the wrapped function with original args and the new, say, **expandedargs (note the double asterisks to explode the keywords). Problems arise when mixing positional and keyword args.

Categories : Python

How to parse HTTP request with a missing content type in Express/ NodeJs, by assuming a default content type?
You have a bunch of options including manually invoking the express (connect, really) middleware functions yourself (really, go read the source code. They are just functions and there is no deep magic to confuse you). So: function defaultContentTypeMiddleware (req, res, next) { req.headers['content-type'] = req.headers['content-type'] || 'application/json'; next(); } app.use(defaultContentTypeMiddleware); app.use(express.bodyParser());

Categories : Javascript

Special 301 redirection rules
This is code needed on DOCUMENT_ROOT/.htaccess on new.com: Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^(www.)?new.com$ [NC] RewriteRule ^$ http://new.com/main [R=301,L] This is code needed on DOCUMENT_ROOT/.htaccess on old.com: Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^(www.)?old.com$ [NC] RewriteRule ^$ http://new.com/main [R=301,L] RewriteCond %{HTTP_HOST} ^(www.)?old.com$ [NC] RewriteRule ^(.+)$ http://new.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^([^.]+).old.com$ [NC] RewriteRule ^$ http://%1.new.com/main [R=301,L] RewriteCond %{HTTP_HOST} ^([^.]+).old.com$ [NC] RewriteRule ^(.+)$ http://%1.new.com/$1 [R=301,L]

Categories : Htaccess

How can I change the home page of a site in Orchard CMS based on rules such as the time of day, or the visitor's device?
The easiest way would be to override the route for "/" to point to your custom controller. Make decision there and either perform a redirect, transfer the request or return varying results. It could also be done on a lower level but this is way more complicated (using custom route implementation, route handler etc. - similar to what Orchard.Alias module does). Extending Orchard.Alias to take into account custom logic in addition to or replacing the current simple path-matching logic would be a way to go then.

Categories : C#

Spring Android Get Request implementation : Could not extract response: no suitable HttpMessageConverter found for response type and content type
Your server returns an XML content but says it returns HTML content (content type is text/html according to the error message) and thus the parsing failed. You need to make sure your server returns something like text/xml and also that you have the correct converters in you rest template object. Edit: Try to add this message converter. Put it first (before StringHttpMessageConverter and SourceHttpMessageConverter) Jaxb2RootElementHttpMessageConverter jaxbMessageConverter = new Jaxb2RootElementHttpMessageConverter(); List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.TEXT_HTML); jaxbMessageConverter.setSupportedMediaTypes(mediaTypes); messageConverters .add(jaxbMessageConverter);

Categories : Android

Nginx rewrite rules with try_files
If you need just to rewrite that one css.css file to wp-admin/admin-post.php?action=thesis_do_css then try this: if ($request_filename ~ wp-content/thesis/skins/classic-r/css.css ) { rewrite ^ http://mydomain.com/wp-admin/admin-post.php?action=thesis_do_css? permanent; } That should be within your server{ block. Make sure to change mydomain.com to your actual domain, of course. I hope that helps.

Categories : Htaccess

What is content-type and datatype in an AJAX request?
contentType is the type of data you're sending, so application/json; charset=utf-8 is a common one, as is application/x-www-form-urlencoded; charset=UTF-8, which is the default. dataType is what you're expecting back from the server: json, html, text, etc. jQuery will use this to figure out how to populate the success function's parameter. If you're posting something like: {"name":"John Doe"} and expecting back: {"success":true} Then you should have: var data = {"name":"John Doe"} $.ajax({ dataType : "json", contentType: "application/json; charset=utf-8", data : JSON.stringify(data), success : function(result) { alert(result.success); // result is an object which is created from the returned JSON }, }); If you're expecting the following: <div>S

Categories : Jquery

Nginx 'rewrite or internal redirection cycle while internally redirecting' resulting in 500
Have you tried something like this? (specific to Magento maybe) server { listen 80 default; ssl off; root /var/www/magento; server_name mydomain.com.au; location / { index index.html index.php; try_files $uri $uri/ @handler; expires 30d; } location ^~ /app/ { deny all; } location ^~ /includes/ { deny all; } location ^~ /lib/ { deny all; } location ^~ /media/downloadable/ { deny all; } location ^~ /pkginfo/ { deny all; } location ^~ /report/config.xml { deny all; } location ^~ /var/ { deny all; } location /var/export/ { ## Allow admins only to view export folder auth_basic "Restricted"; ## Message shown in login window a

Categories : Wordpress

Nginx rewrite some matching rules are not working
Actually i don't like neither of the methods, it might be working but it's not really the best way to write it, so lets try something different. location *~ ^/(contact|privacy|terms|faq)/?$ { try_files $uri $uri/ /index.php?v=$1; } location *~ ^/(twitter|facebook|login)/?$ { try_files $uri $uri/ /index.php?v2=$1; } location / { try_files $uri $uri/ /index.php; } o and I never heard of a last; break; it's probably working only because nginx is ignoring the last part of it, it's either a last or a break,

Categories : PHP

How to rewrite rules with nginx regular expressions
Ok this is a bit too specific redirect but as far as I understand is you don't need any thing more than this location /local/airports/(.*)-2 { return 301 http://example.com/local/airports/$1; }

Categories : Nginx

setting the request header content-type with POST
I think that your url is corrupted, you missed / and ?: url: 'http://www.mywebsite.com/?'+"token="+token+"&account="+account+"&version=1.0&method=put", Moreover you shuldn't use global urls (with http), because they are blocked by browser... url: "?token="+token+"&account="+account+"&version=1.0&method=put",

Categories : Javascript

GET Request with Content-Type and Accept header with JAX-RS Jersey 2.2
The Accept header tells the server what your client wants in the response. The Content-Type header tells the server what the client sends in the request. So the two are not the same. If the server only accepts application/json, you must send a request that specifies the request content: Content-Type: application/json That's why your edited code works. Edit In your first code you use WebTarget.request(MediaType... acceptedResponseTypes). The parameters of this method define the accepted response media types. You are using Innvocation.Builder.accept(MediaType... mediaTypes) on the result of this method call. But accept() adds no new header, it is unnecessary in your first code. You never specify the content type of your request. Since the server expects a Content-Type header, it

Categories : Web Services

Firefox not setting the right content-type for multipart request
I use Firefox to send MPE requests via FormData regularly, and was doing so without issue in 21 for some time. It has to be some plugin you have installed, I would think. Disable all Firefox extensions and try again.

Categories : Javascript

send Http request with Content Type application Json on C#
Assuming you have a class like this to represent the payload, class Payload { public Dictionary<string, string> data { get; set; } public string consolidationKey { get; set;} public long expiresAfter { get; set; } } you can use HttpClient, like this. string url = "http://api.amazon.com/messaging/registrations/1234/messages"; var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Bearer", "token"); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("X-Amzn-Type-Version", "com.amazon.device.messaging.ADMMessage@1.0"); client.Default

Categories : C#

AngularJS $http DELETE request Content-Type header
I found workaround: https://github.com/angular/angular.js/issues/2149#issuecomment-22664501 I hope somebody merge this fix to angularjs master.

Categories : Angularjs

How to create an endpoint that accepts any content type in the request body using ASP.Net Web API
You can bypass formatters entirely by reading the content yourself. Here's an example: public async Task Post() { string content = await Request.Content.ReadAsStringAsync(); // Store away the content } This doesn't require you to use or define any formatters at all.

Categories : Asp Net

Nginx https redirects - stop further rules processing
I usually like to use return instead of rewrite for redirects, try matching the path with a location block location ~ /path/resource(.*) { return 301 $scheme://newdomain.com/newpath/resource$1; } I think this way you know for sure there will be no further processing, because it's only 1 line, try it and tell me how it goes. PS: This will maintain the $scheme of the request, requests to http:// will be redirected to a http:// and https:// will be redirected to https://

Categories : Http

nginx rewrite rules failing - causing 503 errors
This isn't a real answer yet, but a rewrite for your redirect block ( until you provide more info on the error log ) Also please verify that the php sock file is actually located at /tmp/website.co.sock change this server { listen *:80; server_name website.co; rewrite ^(.*) http://www.website.co$1 permanent; } to this server { listen 80; server_name website.co; return 301 $scheme://www.website.co$request_uri; } It's more efficent because it doesn't need a rewrite engine.

Categories : Nginx

Post routing disambiguation based on content type
First, create the following class: public class ButtonAttribute : ActionMethodSelectorAttribute { public string ButtonName { get; set; } public override bool IsValidForRequest( ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo) { return controllerContext.Controller.ValueProvider .GetValue(ButtonName) != null; } public ButtonAttribute(string buttonName) { ButtonName = buttonName; } } Then, in the view, add the name attribute to your buttons: <form action="~/Sample/Post" method="post"> <input type="text" name="x" value="test" /> <input type="number" name="y" value="123" /> <input type="submit" value="First button" name="submit1" /> <input type="su

Categories : C#

send post Https request with Content Type application Json on C#
Just looking at this quickly it seems like this line of code is wrong. var result = client.PostAsJsonAsync<Dictionary<string, Object>>(url, data).Result; based on fact that you're saying amazon wants the post json to look like this. {"data":{"message":"value1","title":"value2"},"consolidationKey":"Some Key","expiresAfter":86400} It seems like you should be passing your var content to the post rather than var data. I.e. var result = client.PostAsJsonAsync<Dictionary<string, Object>>(url, content).Result;

Categories : C#

Invalid content type: application/x-www-form-urlencoded on request using httparty
That should probably be: data = HTTParty.post(url, :body => request, :headers => {"Content-Type" => "application/xml"}) Don't worry about content-length, that's HTTParty's job.

Categories : Ruby On Rails

POST request with Multipart/form-data. Content-type not correct
your code looks correct. requests.post('http://url.com', files={'name': 'John Doe'}) ... and should send a 'multipart/form-data' Post. and indeed, I get something like this posted: Accept-Encoding: gzip, deflate, compress Connection: close Accept: */* Content-Length: 188 Content-Type: multipart/form-data; boundary=032a1ab685934650abbe059cb45d6ff3 User-Agent: python-requests/1.2.3 CPython/2.7.4 Linux/3.8.0-27-generic --032a1ab685934650abbe059cb45d6ff3 Content-Disposition: form-data; name="name"; filename="name" Content-Type: application/octet-stream John Doe --032a1ab685934650abbe059cb45d6ff3-- I have no idea why you'd get that weird Content-Type header: Content-Type: application/x-pandoplugin I would begin by removing Pando Web Plugin from your machine completely, and then try

Categories : Python

jQuery doesn't send post request with content type application/json
Access Control Origin things. Setting of Content-Type header in the JavaScript was not allowed by browser. The solution is to modify the response headers (example in Java): HttpServletResponse hresp = (HttpServletResponse) resp; hresp.addHeader("Access-Control-Allow-Origin", "*"); hresp.addHeader("Access-Control-Allow-Headers", "X-Requested-With,Content-Type"); It is not jquery-specific, but it applies to every AJAX request as well (Dojo or plain javascript).

Categories : Javascript

Default x-www-form-urlencoded content type for http request body in web services
As per the HTTP spec, you can send any content type you like in an HTTP response as long as you provide the appropriate Content-type header. The main benefit of JSON and XML over a plain query string is that they support hierarchies and complex data structures, e.g.: {"cars":[{"manufacturer":"Ford"}, {"manufacturer":"GM"}]} or <cars> <car> <manufacturer>Ford</manufacturer> </car> <car> <manufacturer>GM</manufacturer> </car> </cars> These kinds of structures are usually very useful for webservices, and can't really be achieved with a plain query string.

Categories : Xml

jquery.ajax post request missing content-type in IE9, works in Chrome
$.ajax uses XDomainRequest in order to allow AJAX applications to make safe cross-origin requests In Internet Explorer 8, the XDomainRequest object was introduced. This object allows AJAX applications to make safe cross-origin requests directly by ensuring that HTTP Responses can only be read by the current page if the data source indicates that the response is public but unfortunately only text/plain is supported for the request's Content-Type header In the original incarnation of the XDomainRequest object, we allowed specification of the Content-Type for a POST request. It was pointed out that this violated our goal of emitting only requests that HTML Forms can issue, because HTML Forms are limited to sending data in three different content types: text/plain, ap

Categories : Internet Explorer

Order of request parameters for content-type application/x-www-form-urlencoded in Spring MVC
Your message converter does not work with the native request but with a HttpInputMessage parameter. That is a Spring class. The inputMessage.getBody() is were your problem arises. By default, a ServletServerHttpRequest (another Spring class) is used which has something like this in its getBody() method: public InputStream getBody() throws IOException { if (isFormSubmittal(this.servletRequest)) { return getFormBody(this.servletRequest); } else { return this.servletRequest.getInputStream(); } } which delegates to a private implementation like this: private InputStream getFormBody(HttpServletRequest request) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(bos, FORM_CHARSET);

Categories : Java

Change UICollectionViewCell content and nib layout based on data
You should register each nib file you need in viewDidLoad, something like this (substituting the correct names for the nib file and the identifier): [self.collectionView registerNib:[UINib nibWithNibName:@"RDCell" bundle:nil] forCellWithReuseIdentifier:@"FirstType"]; Then, in itemForRowAtIndexPath, test for type and return the correct type of cell: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (type = @"firstType") { FirstCell *cell = (FirstCell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"FirstType" forIndexPath:indexPath]; return cell; }else{ SecondCell *cell = (SecondCell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"Sec

Categories : Iphone

Can I change the version (or content) of a site based on a user ID
You can make course id and assign it to the userid so when some one will login based on course they have chosen you can show them specific part of site by checking course id from users table for that user.

Categories : PHP

Change corresponding div content based from selection in an array of dropdowns
try following instead: <select id="selectField1" style="padding-left: 20px;width:150px"> <option value="option1">Cat</option> <option value="option2">Dog</option> <option value="option3">Lion</option> </select> <select id="selectField2" style="padding-left: 20px;width:150px"> <option value="option1">Cat</option> <option value="option2">Dog</option> <option value="option3">Lion</option> </select> <div id="option1" class="block">Felis catus</div> <div id="option2" class="block">Canis lupus familiaris</div> <div id="option3" class="block">Panthera leo</div> $('.block').hide(); $('#selectField1,#selectField2').

Categories : Jquery

Flask - How do I read the raw body in a POST request when the content type is "application/x-www-form-urlencoded"
You can get the post data via request.form.keys()[0] if content type is application/x-www-form-urlencoded. request.form is a multidict, whose keys contain the parsed post data.

Categories : Python

Request header field Content-Type is not allowed by Access-Control-Allow-Headers AngularJS
Update Your plnkr worked for me... sort of. I get the following response: {"results":"Sorry, 'json' key expected in post data. For example { "json": "{...}" }. Please check the Blitline examples."} According to the docs: A job is a collection of 1 or more functions to be performed on an image. Data submitted to the job api must have a key of "json" and a value that is a string. The string must contain properly formatted JSON. You should be submitting your POST in a format like this: angular.module('myApp', ['blitline']) .config(['$blitlineGlobalProvider', function($blitlineGlobalProvider) { $blitlineGlobalProvider.options({ json: '{"application_id": "YOUR_ID","version": 2,"src": "http://cdn.blitline.com/filters/boys.jpeg","functions": [{"name": "resize_to_fit","

Categories : Javascript

Change the content-type of a file from within the browser?
I tried something similar some time ago. I used JQuery to parse text as Json or html. In case of HTML I appended it to directly to the DOM. check parseHTML()

Categories : HTML

how to change post['Content-Type'] in angularjs
Have a look at this: How can I make angular.js post data as form data instead of a request payload? Alternatively, you could do the following: $http.post('file.php',{ 'val': val }).success(function(data){ console.log(data); }); PHP $post = json_decode(file_get_contents('php://input')); $val = print_r($post->val,true);

Categories : Angularjs

On iPad, how do i change the content of one UITableView based on a selected Cell from another?
What you describe is a standard master-detail interface. I guess the detail view controller has a property defined in the .h file where you can set the new 'detail item'. If not, you need to add one (and you must currently have one in the init method or something). Implement the setter method for that property, update the detail item and then reloadData. This way you're just updating the existing view controller rather than trying to create a new one each time. I'd recommend you create a new iPad (or universal) project in Xcode, select the master-detail project template and have a look at the code it contains.

Categories : IOS

Change table cell contents based on content overflow
Either set the height of the cell and and set overflow:hidden;, which is kinda ugly, or split up the long comment and put the extra into a hidden span and use jquery to show hide it fiddle HTML <table> <tr> <td valign="top" width="100px" >comment 1:</td> <td class="smallComment">Blah blah blah blah blah blah blah blah blah blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha blah blah blah blha b

Categories : Javascript

Drupal - dynamically add class to wrapping div based on panel pane content node type
Find the tpl.php file that prints that panel layout from the panels module (it can be found under "panels/plugins/layouts/YOUR_LAYOUT" folder) and copy it in your theme folder. In the tpl.php file add the php code the same way you edit drupal themes.

Categories : Drupal

WPF how to change contextmenu items based on treeviewitem type?
I'm assuming you are binding your TreeView to a list of items. If so, are or can the first and second tier of items be of different data types? Then, you can do a HierarchicalDataTemplate for your first tier type and a DataTemplate for your second tier type as such: <HierarchicalDataTemplate DataType="{x:Type local:FirstTierType}" ItemsSource="{Binding Items}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}" /> </StackPanel> </HierarchicalDataTemplate> <DataTemplate DataType="{x:Type local:SecondTierType}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}" /> <StackPanel.ContextMenu> <ContextMenu> <MenuItem Header="wh

Categories : C#

change Content-type to "application/json" POST method, RESTful API
Posting a JSON object is quite easy in Angular. All you need to do is the following: Create a Javascript Object I'll use your exact properties from your code. var postObject = new Object(); postObject.userId = "testAgent2"; postObject.token = "testAgent2"; postObject.terminalInfo = "test2"; postObject.forceLogin = "false"; Post the object to the API To post an object to an API you merely need a simple $http.post function. See below: $http.post("/path/to/api/", postObject).success(function(data){ //Callback function here. //"data" is the response from the server. }); Since JSON is the default method of posting to an API, there's no need to reset that. See this link on $http shortcuts for more information. With regards to your code specifically, try changing your save metho

Categories : Angularjs



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.