I am working on a TinyMCE plugin that will be very simple. I will supply URL, plugin will download page HTML from that given URL and paste the page body into to TinyMCE editor. I have however came up with encoding problem. My page is using utf-8 encoding, but target page is using windows-1250 encoding. When I try to download URL content the result will look like shown below. If the target HTML page uses utf-8 everything is working fine.
My Ajax:
$.ajax({
url: url,
type: 'get',
contentType: 'text/html; charset=windows-1250',
async: false,
success: function (data) {
result = data;
}
});
Result contains text:
Zbo�� mus� b�t fakturov�no v obdob� akce.
Akce je omezena na maxim�ln� 5ks kod� na resellera.
Is there a way how to convert HTML stored in result variable from windows-1250 to utf-8? (using Javascript preferably.. I can do this using C#, but that is not possible in this case)
Thanks for your help!
Headers:
Request:
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:cs-CZ,cs;q=0.8
Connection:keep-alive
Content-Type:text/html; charset=windows-1250
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
X-Requested-With:XMLHttpRequest
Response:
Accept-Ranges:bytes
Content-Length:7365
Content-Type:text/html
Date:Wed, 06 Nov 2013 13:18:01 GMT
ETag:"5c9ff138d7dace1:0"
Last-Modified:Wed, 06 Nov 2013 10:01:54 GMT
Server:Microsoft-IIS/7.5
X-Powered-By:ASP.NET
Related
I'm trying to setup Fine-uploader s3 with cross domain signing. I've been struggling with it for two weeks now, going through every article on the internet and still can't get this to work. I'm, with exaggerating, very frustrated. I've started questioning every line of code and I get nowhere..
I keep receiving the following errors in the browser console:
XHR finished loading: OPTIONS "https://myserver.com/vendor/fineuploader/php-s3-server/endpoint-cors.php?v4=true".
util.js:241 [Fine Uploader 5.15.6] Invalid policy document or request headers!
XHR finished loading: POST "https://myserver.com/vendor/fineuploader/php-s3-server/endpoint-cors.php?v4=true".
util.js:241 [Fine Uploader 5.15.6] Policy signing failed. Invalid policy document or request headers!
I'm using the php server provided by fineuploader on github to sign documents. Here I've set my constants and modified
'access-control-allow-origin: https://myserver.com' and 'access-control-allow-credentials: true'.
My javascript uploader script client-side looks like this.
var uploader = new qq.s3.FineUploader({
element: document.getElementById("uploader"),
debug: true,
request: {
endpoint: 'BUCKET_NAME.s3-accelerate.amazonaws.com',
accessKey: 'ACCESS_KEY'
},
cors: {
//all requests are expected to be cross-domain requests
expected: true,
//if you want cookies to be sent along with the request
sendCredentials: true
},
objectProperties: {
bucket: 'BUCKET_NAME',
host: 's3-accelerate.amazonaws.com' // only needed for version 4 signatures
},
signature: {
endpoint: 'https://myserver.com/vendor/fineuploader/php-s3-server/endpoint-cors.php',
version: 4
},
uploadSuccess: {
endpoint: 'https://myserver.com/vendor/fineuploader/php-s3-server/endpoint-cors.php?success'
},
iframeSupport: {
localBlankPagePath: '/success.html'
},
validation: {
allowedExtensions: ["jpeg", "jpg", "png"],
acceptFiles: "image/jpeg, image/png",
sizeLimit: 10000000,
itemLimit: 1
},
retry: {
enableAuto: true // defaults to false
},
paste: {
targetElement: document,
promptForName: true
}
});
This is my header information
Request URL:https://MYSERVER.com/vendor/fineuploader/php-s3-server/endpoint-cors.php?v4=true
Request Method:OPTIONS
Status Code:200 OK
Remote Address:MY_IP
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Methods:OPTIONS
Access-Control-Allow-Origin:https://MY_WEBSITE.com
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=UTF-8
Date:Wed, 31 Jan 2018 17:45:06 GMT
Host:127.0.0.1:8000
Server:nginx/1.10.3 (Ubuntu)
Transfer-Encoding:chunked
X-Powered-By:PHP/7.0.22-0ubuntu0.16.04.1
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:da-DK,da;q=0.9,en-US;q=0.8,en;q=0.7
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:aeoeaa.club
Origin:https://MY_WEBSITE.com
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Query String Parameters
view source
view URL encoded
v4:true
And
Request URL:https://MYSERVER/vendor/fineuploader/php-s3-server/endpoint-cors.php?v4=true
Request Method:POST
Status Code:200 OK
Remote Address:MY_IP
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:https://MYWEBSITE.com
Connection:keep-alive
Content-Type:application/json
Date:Wed, 31 Jan 2018 17:45:07 GMT
Host:127.0.0.1:8000
Server:nginx/1.10.3 (Ubuntu)
Transfer-Encoding:chunked
X-Powered-By:PHP/7.0.22-0ubuntu0.16.04.1
Request Headers
view source
Accept:application/json
Accept-Encoding:gzip, deflate, br
Accept-Language:da-DK,da;q=0.9,en-US;q=0.8,en;q=0.7
Connection:keep-alive
Content-Length:461
Content-Type:application/json; charset=UTF-8
Host:MYSERVER.com
Origin:https://MYWEBSITE.com
Referer:https://MYWEBSITE.com/pages/testpage
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Query String Parameters
view source
view URL encoded
v4:true
Request Payload
view source
{expiration: "2018-01-31T17:50:06.323Z",…}
conditions
:
[{acl: "private"}, {bucket: "MY_BUCKET_NAME"}, {Content-Type: "image/jpeg"},…]
expiration
:
"2018-01-31T17:50:06.323Z"
Everything should be working but I still get the same error. I don't want any of the complicating features. I just want a simple upload to s3. But this seems impossible. I'll gladly supply more info. Anything to get this done. I'll even send a bottle of wine to the one solving it. Nothing I do helps..
Trying to embed PowerBI dashboard into angular App. The API call to get access token is working in API is working in Postman but not working in Angular $http.post
Here is my http request:
Request URL:https://login.microsoftonline.com/common/oauth2/token
Request Method:POST
Status Code:400 Bad Request
Remote Address:104.211.216.34:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Cache-Control:no-cache, no-store
Content-Length:435
Content-Type:application/json; charset=utf-8
Date:Tue, 28 Nov 2017 12:39:04 GMT
Expires:-1
P3P:CP="DSP CUR OTPi IND OTRi ONL FIN"
Pragma:no-cache
Server:Microsoft-IIS/8.5
Set-Cookie:esctx=AQABAAAAAABHh4kmS_aKT5XrjzxRAtHzOEDuOCnOGQdXuNJYF9t_l4l8QbiGM-1SOn4WhmgW5oU1BTHew-wFbpdzDe250yG1ODXnl9crMy97-PJdBUTJD2hCZ0fjpleNFz13Xbl3nDt21xoySABfsdxlxd8ODv8ryZ_n2CwnYMpM_yEoQG5tSxlh-SdOviP8tF3-n_uBqZwgAA; domain=.login.microsoftonline.com; path=/; secure; HttpOnly
Set-Cookie:x-ms-gateway-slice=004; path=/; secure; HttpOnly
Set-Cookie:stsservicecookie=ests; path=/; secure; HttpOnly
Strict-Transport-Security:max-age=31536000; includeSubDomains
X-Content-Type-Options:nosniff
x-ms-request-id:5f039662-e0ce-425a-9e38-1593c64c7b00
X-Powered-By:ASP.NET
Request Headers
view source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-GB,en-US;q=0.9,en;q=0.8
Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Length:188
Content-Type:application/x-www-form-urlencoded
Host:login.microsoftonline.com
Origin:http://evil.com/
Referer:http://localhost:9000/power-bi
roleId:57be85636318773723861b99
token:W0JANTc3YjEwMTY
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
Form Data
view source
view URL encoded
{"grant_type":"password","client_id":"clientId","resource":"https://analysis.windows.net/powerbi/api","username":"username","password": "password"}
Response is :
correlation_id : "1e68335a-6b6d-441d-90d3-eb8c88929a37"
error:"invalid_request"
error_codes:[90014]
error_description:"AADSTS90014: The request body must contain the following parameter: 'grant_type'.
↵Trace ID: 5f039662-e0ce-425a-9e38-1593c64c7b00
↵Correlation ID: 1e68335a-6b6d-441d-90d3-eb8c88929a37
↵Timestamp: 2017-11-28 12:39:05Z"
timestamp:"2017-11-28 12:39:05Z"
trace_id:"5f039662-e0ce-425a-9e38-1593c64c7b00"
can anyone please help me out of this hitch??
I got the Solution. I got that error i was making API call correctly. it expects data to be sent in 'Content-Type':'application/x-www-form-urlencoded' and data is serialised.
This code worked :
$http({
headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'},
url: 'https://login.microsoftonline.com/common/oauth2/token',
method: 'POST',
transformRequest: $httpParamSerializer,
transformResponse: function (x) {
return angular.fromJson(angular.fromJson(x));
},
data: {
grant_type:'password',
client_id: "client_id",
resource:'https://analysis.windows.net/powerbi/api',
username:"username",
password: "pwd",
client_secret: "client_secret"
}
})
I hope this answer will be useful anyone who face same problem in future.
I have a text box to enter text, but the server can't handle double byte space.
I'd like to convert it to regular space before sending.
Tried to do
var content = "よろしいでしょう キャンセル"
content = content.replace(" ", " ");
but now IDE is screaming that it can't save it that way.
is there standard way to do it?
The request header from Fiddler:
POST /blablabla/SearchTerm HTTP/1.1
Host: localhost
Connection: keep-alive
Content-Length: 290
Accept: application/json
Origin: http://localhost
X-Requested-With: XMLHttpRequest
Accept-Language: en-US
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Content-Type: application/json
Referer: http://localhost/blablabla
Accept-Encoding: gzip, deflate
and the request itself is from fiddler:
{...."content":"\u3088\u308d\u3057\u3044\u3067\u3057\u3087\u3046\u3000\u30ad\u30e3\u30f3\u30bb\u30eb"....}
and the Ajax call from javascript
// Invoke request to server and register to the success and failure events
Ext.Ajax.request({
url: '/blablabla/SearchTerm',
method: "POST",
headers: this.header || {
"Content-Type": "application/json",
"Accept": "application/json"
},
jsonData: {
content: content,
},
timeout: this.configuration.getAjaxRequestTimeout(),
success: searchCompletedSuccessDelegate,
failure: searchCompletedFailureDelegate
});
I guess that your IDE doesn't support the encoding of the space \u3000 , so you can use unicode notation with \u escape (don't know the real name):
//will work in any case
var content = "\u3088\u308d\u3057\u3044\u3067\u3057\u3087\u3046\u3000\u30ad\u30e3\u30f3\u30bb\u30eb";
content.replace("\u3000"," ")
I don't know for VS, but some IDE can configure the file to be encoded into UTF-8 to avoid that problem.
I have this javascript function that I use in an MVC project. It's been working fine, no code has changed, other than some nuget packages have been updated since the last time I tested it (not sure which ones). Now suddenly I'm getting a parse error. The parameter being passed is simply 'indoor' or 'outdoor', and just to make sure that had nothing to do with the issue, I hard-coded it instead of passing it, both with and without the JSON.stringify to see if that mattered, which it didn't. Any ideas why this is suddenly breaking?
function LoadHobbies(category) {
var data = {
type: category
};
return $.ajax({
type: 'post',
contentType: 'application/json; charset=utf-8',
url: '/Hobby/LoadHobbies',
dataType: 'json',
data: JSON.stringify(data)
});
}
Remote Address:[::1]:9925
Request URL:http://localhost:9925/Hobby/LoadHobbies
Request Method:POST
Status Code:302 Found
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:17
Content-Type:application/json; charset=UTF-8
Host:localhost:9925
Origin:http://localhost:9925
Referer:http://localhost:9925/Account/Index
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payloadview source
{type: "indoor"}
type: "indoor"
Response Headersview source
Cache-Control:private
Content-Length:162
Content-Type:text/html; charset=utf-8
Date:Sat, 10 Jan 2015 01:28:13 GMT
Location:/Login/Index?ReturnUrl=%2fHobby%2fLoadHobbies
Server:Microsoft-IIS/8.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:5.2
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?RDpcVXNlcnNcQW5kcmV3XERvY3VtZW50c1xjb2RlXEhvYmJ5TWF0cml4U29sdXRpb25NVkNcSG9iYnlNYXRyaXhXZWJcSG9iYnlcTG9hZEhvYmJpZXM=?=
Sorry, I'm a moron. I had added a global authentication check a while back, and forgot to put an [AllowAnonymous] attribute on this controller. So I was right about it not reaching the breakpoint, and you were right about the redirect. Sorry I wasted everyone's time.
Thanks,
Andrew
I have a facebook page, and I am trying to upload a video to it that is already hosted on my servers.
I need to do this via javascript, and all I have is the src link (something like https://cdn.whodaman.net/Q45rt7y.mp4) of the video. Being the administrator, I have all required permissions (publish_stream, manage_pages).
The facebook api says that I have to send the data as multipart/form-data which means the video content. So to do this via ajax, I followed this question on stackoverflow, and followed How to send FormData objects with Ajax-requests in jQuery.
Here's my javascript code:
var fd = new FormData();
fd.append( 'source', 'https://cdn.whodaman.net/Q45rt7y.mp4' );
fd.append( 'access_token', testaccessToken);
fd.append( 'title', "Test Video");
$.ajax({
url: "https://graph-video.facebook.com/"+testPageId+"/videos",
data: fd,
processData: false,
contentType: false,
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
}
});
Here's the request and corresponding response:
Request URL:https://graph-video.facebook.com/[my page id]/videos
Request Method:POST
Status Code:400 Bad Request
Request Headers
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:948
Content-Type:multipart/form-data
Cookie: [some cookie data]
Host:graph-video.facebook.com
Origin:http://real.domain.com:8090
Pragma:no-cache
Referer:http://real.domain.com:8090/test/upload
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Request Payload
------WebKitFormBoundaryd8laVBo5HXRTFJnn
Content-Disposition: form-data; name="source"
https://cdn.whodaman.net/Q45rt7y.mp4
------WebKitFormBoundaryd8laVBo5HXRTFJnn
Content-Disposition: form-data; name="access_token"
[my access token]
------WebKitFormBoundaryd8laVBo5HXRTFJnn
Content-Disposition: form-data; name="title"
Test Video
------WebKitFormBoundaryd8laVBo5HXRTFJnn--
Response Headers
Access-Control-Allow-Origin:*
Cache-Control:no-store
Connection:keep-alive
Content-Length:146
Content-Type:application/json; charset=UTF-8
Date:Mon, 11 Nov 2013 13:50:45 GMT
Expires:Sat, 01 Jan 2000 00:00:00 GMT
Pragma:no-cache
WWW-Authenticate:OAuth "Facebook Platform" "invalid_token" "An access token is required to request this resource."
X-FB-Debug:HlhHF7eIBkLbUBktqeWnVv8V3viIeS8jom0WPt1D7fc=
X-FB-Rev:1000997
Facebook is asking for the access token! I'm pretty sure I have the right one, because I'm being able to add a text status post. I have also tried to change the name of the file parameter in form data from source to file to no effect.
So is it even possible to upload a video to facebook via the js sdk directly from the video url? I have a feeling it is, and am quite close to the solution.
Perform a POST request to the graph api Using the file_url field to specify the url for your video and get rid of the source field , no need for a multipart/form-data .