w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How would you implement String to json object unmarshaller for parameter of url-encoded POST?
Shockingly I figured it out myself. Here is working version of universal unmarshaller. implicit def String2JsonParser[T: RootJsonReader] = new FromStringDeserializer[T] { def apply(value: String) = try Right(JsonParser(value).convertTo[T]) catch { case ex: Throwable => Left(spray.httpx.unmarshalling.MalformedContent(ex.getMessage)) } }

Categories : Scala

Two $.post requests one after the other.Second $.post request doesn't get executed
$.post() is an abbreviated form of the $.ajax() structure. I usually prefer to use the $.ajax() structure because: It's easier to see if I've missed anything I can more easily add additional params, such as asynch: false, When new to ajax I found it considerably easier to troubleshoot this structure In your case, you might find your problem easier to solve in a $.ajax() structure, since it would be easier to see that a second ajax call (that depends on the outcome of a first ajax call) must happen in the success function of the first ajax call. Here is a standalone example (too bad jsFiddle cannot handle ajax...): TESTER.PHP <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="

Categories : Ajax

Does ajax post data need to be URI encoded?
No they do not. There is no need for it when it is send as data through Ajax POST. You can send pure JSON unencoded using AJAX var ajaxObject = $.ajax({ url: 'url', type: 'POST', data: JSON.stringify(object_literal); });

Categories : PHP

How to POST chunked encoded data in Python
The code you posted shouldn't have worked correctly. The reason you still get a successful response back is because httpbin.org doesn't currently support chunked transfer encoding. See bug https://github.com/kennethreitz/httpbin/issues/102. Like in the post Piotr linked to above, you're supposed to write out the length of each chunk in hexadecimal and then the chunk itself. I butchered your code for an example. The http://httpbin.org/post endpoint has a form that you can use for testing. That's where I generated the chunk1 and chunk2 form data. import httplib import time chunk1 = "custname=bob&custtel=11111&custemail=bob%40email.com&si" chunk2 = "ze=medium&topping=bacon&delivery=11%3A00&comments=if+you%27re+late+we+get+it+free" if __name__ == "__main__": co

Categories : Python

reading only half content while converting encoded zipped string to normal string in java
Before even answering the question, let me make some comments: There is no need to create a new String from a String constant. String request= "UEsDBBQACAAIAHhoE....." ; Base64.decode does not receive a byte[] to hold the result. So, it is most probably creating the one it returns. In consequence, resByte does not need to be initialized. resByte's declaration should be just byte[] resByte; That said, and without many more details, instruction String s1 = new String(writeByte); will use the platform default encoding (this depends on OS and OS configuration if you have not manually set it). If your encoding is such as UTF-16 (where every character corresponds to 2-bytes), you would be obtaining exactly half the characters the number of bytes in writeByte . If s1 looks garbled (wh

Categories : Java

Post complex type formatted as form-url-encoded using ASP.Net HttpClient
Since you've almost got a solution that does work, I'd say just go with it. Organize your code inside an extension method so that you can post using that, something like: public static async Task<HttpResponseMessage> PostAsFormUrlEncodedAsync<T>( this HttpClient httpClient, T value) { // Implementation } Your implementation just needs to serialize your object into form-encoded values, which you should be able to do easily with reflection. Then you can call the code exactly as you would for JSON or XML.

Categories : C#

Unable to send json string containing encoded string with curl in php
Always turn on error_reporting when you're developing code, otherwise the simplest syntax error looks like a showstopping bug. The line: $string = 'teststring' Is missing a semicolon.

Categories : PHP

Javascript decode JSON string which contains an encoded string
The code returns exactly what it should return. when json_encodein $bar, $bar->foo is a string. this string is escaped to produce a correct output. $bar->foo = json_encode($foo); should be $bar->foo = $foo

Categories : PHP

How to convert from hex-encoded string to a "human readable" string?
Change "hex" to "hex_codec" for Pyton < 3 This applies to python 3+ Possible to use? >>> codecs.decode(b"4f6c6567", "hex_codec") b'Oleg' >>> codecs.getdecoder("hex_codec")(b"4f6c6567") (b'Oleg', 8)

Categories : Python

Prevent copy-pasted base64 encoded images in WordPress post editor
I'm using this plugin to prevent copy-pasted base64 images. It doesn't completely disable it (it will check the editor 1,5 seconds and remove base64 images), but it seems like a decent workaround.

Categories : Wordpress

Parsing string to add to URL-encoded URL
require 'uri' URI.encode("Hello there world") #=> "Hello%20there%20world" URI.encode("hello there: world, how are you") #=> "hello%20there:%20world,%20how%20are%20you" URI.decode("Hello%20there%20world") #=> "Hello there world"

Categories : Ruby On Rails

I am unable to set my string to be encoded in utf-8
Define the encoding of your source file using the # -*- coding: ... header (http://www.python.org/dev/peps/pep-0263/) Then, actually use that encoding (in you editor). In Python 2, use from __future__ import unicode_literals and then, from_google_doc = "Café" actually already is unicode type.

Categories : Python

std::string and UTF-8 encoded unicode
You are talking about Unicode. Unicode uses 32 bits to represent a character. However since that is wasting memory there are more compact encodings. UTF-8 is one such encoding. It assumes that you are using byte units and it maps Unicode characters to 1, 2, 3 or 4 bytes. UTF-16 is another that is using words as units and maps Unicode characters to 1 or 2 words (2 or 4 bytes). You can use both encoding with both string and wchar_t. UTF-8 tends to be more compact for english text/numbers. Some things will work regardless of encoding and type used (compare). However all functions that need to understand one character will be broken. I.e the 5th character is not always the 5th entry in the underlying array. It might look like it's working with certain examples but It will eventually break. st

Categories : C++

Encoded string to Normal string in ios?
Navi Try this .Check code between comment lines - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { NSLog(@"Loaded list of products..."); _productsRequest = nil; NSArray * skProducts = response.products; //////////////////////////////////////// EDIT ////////////////////////////// SKProduct * product = (SKProduct *)skProducts[0]; NSLog(@"naveen =0%@",product.localizedTitle); //////////////////////////////////////////////////////////////////////////// for (SKProduct * skProduct in skProducts) { NSLog(@"Found product: %@ %@ %0.2f", skProduct.productIdentifier, skProduct.localizedTitle, skProduct.price.floatValue); } _completionHandler(YES, skPr

Categories : IOS

Compressing a Base 62(0-9a-zA-Z) encoded string
See the Pigeonhole principle - if you try to put 100 pigeons into 10 holes, some holes will have multiple pigeons. In the same way, for your problem, there will have to be occurrences of two strings compressing to the same string. In these cases, you won't know which string to decompress the compressed string to. So no, you cannot losslessly compress 20 characters to 16 characters (or even 20 to 19 characters) in the same encoding for all possible inputs. If the input were to have some defining characteristics, such as that the only uppercase character will be the first character, the last 3 characters are where the numbers appears, etc., then it will be more compressible and it may be possible. If you had such characteristics (or if you want to convert to a different encoding that ha

Categories : Algorithm

Regex for url-encoded string in .htaccess
So the solution was really easy as it suppose to be: RewriteCond %{HTTP_HOST} ^.*example1.kereell.com$ [NC] RewriteCond %{REQUEST_URI} ^/wp-login.php$ [NC] RewriteCond %{QUERY_STRING} ^action=logout&redirect_to=http[\%A-Z0-9]*www.example2.kereell.com(.*)$ [NC] RewriteRule ^(.*)$ http://www.example2.kereell.com/$1 [R=301,L] Thanks for Qtax that paid my attention to QUERY_STRING!

Categories : Regex

How to run JMeter with different post requests
To do this, use: CSV Data Set, this will export as variables the columns in each row of your CSV Then you just use variables this way ${var1} in Http Request sampler

Categories : Http

Handling Post Requests
There are a number of suitable ways to handle this, and the decision is largely a matter of preference and what you're familiar with. Spring can handle this sort of job quite well. Note: Maven is a build system for Java and some other JVM languages. I recommend using it, but it's not part of Spring; what you're probably looking for is Spring MVC.

Categories : Java

Caching in JAX-RS for POST requests
HTTP has methods that are safe or unsafe, and methods that are idempotent or not idempotet. See the HTTP spec: Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property. You can GET, PUT, or DELETE a Resources as often as you like, the result will be the same, no matter how often you do it. As you see, POST is not idempotet. It makes a difference to POST a request to a Resource once, twice, or more often. That's because the semantics of POST is to create something below the Resource you POST to. Because of all this, it makes no sense to cache the result of a POST request.

Categories : Rest

POST Requests from a Servlet
Your localhost has your localhost IP as a sending IP. Openshift et al has the Openshift et al IP as a sending IP. So the Google API says "I have only seen that localhost IP twice before, that's fine!", whereas it says "I have seen this Openshift IP millions of times before! NO REPLY FOR YOU!"

Categories : Java

How to block IPs for POST requests, but not GET?
Change the order of allow deny like this: <Limit POST PUT DELETE> order allow,deny allow from all deny from 210.5.214.128/29 deny from 210.89.69.160/28 # Hundreds more lines... # My current IP (sample provided here, actual used in reality), to test deny from 100.100.100.100 </Limit> <Limit GET HEAD> order deny,allow allow from all </Limit>

Categories : Apache

Get image type from base64 encoded src string
Test this: <?php $str = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAA...'; function getB64Type($str) { // $str should start with 'data:' (= 5 characters long!) return substr($str, 5, strpos($str, ';')-5); } var_dump(getB64Type($str));

Categories : PHP

Converting a string encoded in utf8 to unicode in C#
Download the web pages as bytes in the first place. Then, convert the bytes to the correct encoding. By first converting it using a wrong encoding you are probably losing data. Especially using ASCII.

Categories : C#

PHP get pdf file from base64 encoded data string
Try this piece of code $pdf_base64 = "base64pdf.txt"; //Get File content from txt file $pdf_base64_handler = fopen($pdf_base64,'r'); $pdf_content = fread ($pdf_base64_handler,filesize($pdf_base64)); fclose ($pdf_base64_handler); //Decode pdf content $pdf_decoded = base64_decode ($pdf_content); //Write data back to pdf file $pdf = fopen ('test.pdf','w'); fwrite ($pdf,$pdf_decoded); //close output file fclose ($pdf); echo 'Done';

Categories : PHP

Substitute multiple parts of a URL with encoded string
The Perl binding operator is =~, not ~=. It is not possible to make two substitutions at once, however it is possible to make the substitution happen as many times as needed with /g: #!/usr/bin/perl use warnings; use strict; my $url = 'http://example.com/?param1=#param1#&param2=#param2#'; my %params = ( param1 => 'hello', param2 => 'world', ); $url =~ s/#(.*?)#/$params{$1}/g; print $url, " "; For encoding of URLs, use URL::Encode.

Categories : Regex

Convert and Display the UTF8 Encoded String
You're showing the text with non-currency symbols... it's as if you're taking the original text, then encoding that as UTF-8, then decoding it as ISO-8859-1. It's just text - you shouldn't need to do anything to it afterwards, and you should never see it in this broken format. If you have to convert the text back to bytes and then to a string again, that means you've already lost, basically. Check the headers on the HTTP response which returns the JSON - I suspect you'll find that it's claiming the data is ISO-8859-1 rather than UTF-8. The actual encoding has to match the encoding that's specified in the headers, otherwise you end up with this sort of effect. Another possibility is that whatever's returning the JSON is accurately giving you the data that it knows about, and that the dat

Categories : Java

I can't parse the data from a JSON encoded string
The JSON is malformed. After I do the stripslashes the JSON should be formed like the following to be valid: { "1": { "QID": "1", "Type": "MC", "Question": "Questionhere", "Options": { "1": "AnswerOpt1" } } }

Categories : PHP

SQL Convert unicode encoded varbinary to string
You should use GetString() method on specific unicode Text.Encoding to convert it back to string. Cast the column to byte[] from reader and then convert that to string using GetString(). string value; using (SqlCommand command = new SqlCommand("select * from InvPstFile", sqlConnection)) { SqlDataReader sdr = command.ExecuteReader(); //Assuming we are just reading 1 row here sdr.Read(); var bytes = (byte[])sdr["OldRegBinary"]; // Based on the original unicode format one of the following should // give you the string value value = System.Text.Encoding.UTF8.GetString(bytes); value = System.Text.Encoding.Unicode.GetString(bytes); value = System.Text.Encoding.Default.GetString(bytes); }

Categories : C#

Decode URL whereas encoded string are in double quotes
First extract the part you want to decode: String str = url.substring(str.indexOf('"') + 1, str.lastIndexOf('"')); Then decode it using StringEscapeUtils.unescapeHtml4: String result = StringEscapeUtils.unescapeHtml4(str);

Categories : Java

Python encoded utf-8 string xc4x91 in Java
Python escapes unicode characters by converting their UTF-8 bytes into a series of xVV values, where VV is the hex value of the byte. This is very different from the java unicode escapes, which are just a single uVVVV per character, where VVVV is hex UTF-16 encoding. Consider: xc4x91 In decimal, those hex values are: 196 145 then (in Java): byte[] bytes = { (byte) 196, (byte) 145 }; System.out.println("result: " + new String(bytes, "UTF-8")); prints: result: đ

Categories : Java

Decode Class from @encoded type string
Unfortunately, I do not think there is a way to be sure that you are working with a class using the encoding. dasblinkenlight has a good idea in the comments, although he didn't support other instance variables. The full format for a class is {CLASSNAME=#IVARS}. However, this could potentially catch other structures as well, as I will explain below. The reason classes are encoded like this are that they are treated just like structures by @encode. The { indicates the start of a structure, and is followed by the structure's name and an equals sign, then the contents, and finally }. The reason all classes have # after the equals sign is that the first element in a class structure is of type Class, and that is how this type is encoded. What this means is that any structure beginning with a

Categories : Objective C

passing a utf8 encoded string to web service
You need to URL encode your string/message. Messages must be URL Encoded before being sent to a webservice as they contain special characters. Function EncodeToUTF(ByVal toEncode As String) As String Dim utf8 As New UTF8Encoding() Dim encodedBytes As Byte() = utf8.GetBytes(toEncode) Dim returnValue As String = utf8.GetString(encodedBytes) '' URL encode your string before pushing it to a web service returnValue = HttpUtility.UrlEncode(returnValue) Return returnValue End Function And, on the other server side, use the following to decode your encoded string: Dim decodedUrl As String = HttpUtility.UrlDecode(encodedUrl) Hopefully, this will solve your issue.

Categories : Asp Net

Under what circumstances can a JSON encoded array become a string?
Once you get the string into JavaScript, you'd have to eval() it to turn it into a JSON object: var reply_json = eval( reply ); Then you can access reply_json.content, reply_json.menu, and so on. Obviously be careful about what it is you're eval'ing, make sure it's from a trusted source and so forth.

Categories : PHP

How to GET and POST requests separately with HttpRequestHandler
The HttpServletRequest provides the method getMethod() Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. Same as the value of the CGI variable REQUEST_METHOD.

Categories : Java

Same Rails 4 routes for GET and POST requests
You can use match as long as you have via: match "user/account" => "user#account", as: :user_account, via: [:get, :post] Edit: Added a as: parameter so that it will be accessible via a url helper. user_account_path or user_account_url in this case.

Categories : Ruby

Why JSF POST requests don't work with PrettyFaces
First of all, thanks for helping. It is something strange, that's why I couldn't isolate the problem (to get it happen in another project), which is not executing the POST requests at first try, but from the second one. I have removed the filters I had in web.xml without any difference. The same behavior. I've just had the idea of testing the project in other Tomee version than 1.5.2. Surprisingly, dev version 1.6.0 from 29.07.2013 seems to don't have this problem. Why didn't I think at this sooner? :( I had to write separate Servlet components for my post functionalities. Aaaah! Well, this means that not PrettyFaces was problematic (Huraay!), but, probably, Apache MyFaces, CDI impl. or something else in Tomee. Uf...I'm so happy that it works now. Thanks again for trying to help. ////

Categories : JSF

IOS http POST requests seem to be empty
Try this function in server side function getRealPOST() { $result = array(); $b = explode("&", urldecode(file_get_contents("php://input"))); foreach($b as $k => $v) { list($ind, $val) = explode("=", $v); $result[$ind] = $val; } return $result; } $post = getRealPOST() echo "<pre>"; print_r($post); hope it will help to get post data in other way not using $_POST

Categories : PHP

Laravel 4 CSRF on all POST requests
In my BaseController I have this: public function __construct() { $this->beforeFilter('csrf', array('on' => array('post', 'delete', 'put'))); $this->beforeFilter('ajax', array('on' => array('delete', 'put'))); } Having such App::before filter is an interesting approach but I don't know which is better?

Categories : PHP

Writing and then reading a string in file encoded in latin1
Your data was written out as UTF-8: >>> 'On écrit ça dans un fichier.'.encode('utf8').decode('latin1') 'On écrit ça dans un fichier.' This either means you did not write out Latin-1 data, or your source code was saved as UTF-8 but you declared your script (using a PEP 263-compliant header to be Latin-1 instead. If you saved your Python script with a header like: # -*- coding: latin-1 -*- but your text editor saved the file with UTF-8 encoding instead, then the string literal: s='On écrit ça dans un fichier.' will be misinterpreted by Python as well, in the same manner. Saving the resulting unicode value to disk as Latin-1, then reading it again as Latin-1 will preserve the error. To debug, please take a close look at print(s.encode('unicode_escape')) in the fi

Categories : Python

How to read a UTF-8 encoded list of string tokens into a vector?
You can either read it in with read.table() and then extract the column as a vector, or with scan(). vect <- scan(file="path/to/file1.txt", what=character(0) ) You would not need to use UTF-8 as the encoding, since you know that it is the default, but there is the option of doing so: vect <- scan(file="path/to/file1.txt", what=character(0), encoding="UTF-8" ) The NEWS file for R 3.0.0 said: " o readLines() and scan() (and hence read.table()) in a UTF-8 locale now discard a UTF-8 byte-order-mark (BOM). Such BOMs are allowed but not recommended by the Unicode Standard: however Microsoft applications can produce them and so they are sometimes found on websites. The encoding name "UTF-8-BOM" for a connection will ensure that a UTF-8 BOM is discarded. " So perhaps the need for

Categories : String



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