I'm trying to download an Excel file from my web page. In the local environment, everything works fine. But in Azure the encoding of the file name gets screwed up. I have already set the globalization tag in web.config as follows:
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>
Here is how the response is built:
string name = v_NomeArquivo + ".xlsx";
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + name);
Response.BinaryWrite(v_ExcelPackage.GetAsByteArray());
Response.End();
The headers on Azure:
cache-control: private
content-disposition: attachment; filename=Relatório Contrato Limpeza e Higinenização - 2020-10-06_10-55-26.xlsx
content-type: application/ms-excel
date: Tue, 06 Oct 2020 13:55:26 GMT
server: Microsoft-IIS/10.0
status: 200
x-aspnet-version: 4.0.30319
x-powered-by: ASP.NET
And on local:
Cache-Control: private
content-disposition: attachment; filename=Relatório Contrato Limpeza e Higinenização - 2020-10-06_10-58-59.xlsx
Content-Type: application/ms-excel
Date: Tue, 06 Oct 2020 13:58:59 GMT
Server: Microsoft-IIS/10.0
Transfer-Encoding: chunked
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
The only difference is the filename getting messed up and the Transfer-Encoding, could it be it?
You need to use System.Web.HttpUtility.UrlEncode method.
Ex:
string name = System.Web.HttpUtility.UrlEncode(v_NomeArquivo + ".xlsx", System.Text.Encoding.UTF8);
Related
Retrofit 2 having problem sending #FormUrlEncoded #Field no parameter is passed.
#FormUrlEncoded
#POST("GetRechargeDetail")
Call <List<IglGatewayOrderDetail>> Fetch_OrderDetail_IGL(#Field("Bpno") String Bpno);
D/OkHttp: <-- 500 https://test.com/test/test.asmx/GetRechargeDetail (188ms)
cache-control: private
D/OkHttp: content-type: text/plain; charset=utf-8
server: Microsoft-IIS/10.0
x-aspnet-version: 4.0.30319
x-powered-by: ASP.NET
x-powered-by-plesk: PleskWin
access-control-allow-origin: *
date: Sat, 23 Apr 2022 11:21:18 GMT
content-length: 396
D/OkHttp: System.InvalidOperationException: Missing parameter: Bpno.
at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
<-- END HTTP (396-byte body)
earlier everything was working fine if I remove FormUrlEncoded and change Field to Query it works but in some API i need URL encoded so i cannot remove FormUrlEncoded.
I am trying to publish contact group into Azure Active Directory.
Steps that I followed:
Register Application in Azure and get the Tenant ID and Client ID.
Send the CFHTTP Request for token (I need help here)
Send token and other parameters (I need help here) to publish the contact groups
cfhttp(method="POST", charset="utf-8", url="https://login.microsoftonline.com/common/oauth2/v2.0/response_type=code", result="result") {
cfhttpparam(name="Content-Type", type="header", value="application/x-www-form-urlencoded");
cfhttpparam(name="client_id", type="formfield", value="28d5e75-a762-45a2-9504-e9bbaa3294af");
cfhttpparam(name="grant_type", type="formfield", value="authorization_code");
cfhttpparam(name="mimetype", type="header", value="application/xml");
}
Response:
Header HTTP/1.1 404 Not Found Cache-Control: private Strict-Transport-Security: max-age=31536000; includeSubDomains X-Content-Type-Options: nosniff x-ms-request-id: caeef2f8-71a0-45f6-8820-63d880f02700 x-ms-ests-server: 2.1.10244.21 - WST ProdSlices P3P: CP="DSP CUR OTPi IND OTRi ONL FIN" Set-Cookie: x-ms-gateway-slice=prod; path=/; SameSite=None; secure; HttpOnly Date: Mon, 23 Mar 2020 18:20:59 GMT Connection: close Content-Length: 0
Mimetype Unable to determine MIME type of file.
I am trying to download some playlists off soundcloud and found a site that does this for you. Of course if the playlist is long, then it's super tedious to click each link to download. So I saved the HTML of the page and have parsed out the links. The idea is to use urllib or requests to download the files.
Here's my code:
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
track_url = 'https://scdownloader.io/download?track=zandex-hazerback-erox-stroke-bth-release&token=be1bc7997695495f756312886f566110'
track_name = 'BANG_THE_HOUSE___zandex-hazerback-erox-stroke-bth-release.mp3'
output_file = '/Users/ms/Desktop/playlist/{}'.format(track_name)
urllib.request.urlretrieve(track_url, output_file)
When I run the above code, it does save the file, but it arrives as a 1 byte file only.
I've tried other permutations using requests but basically either it doesn't work, downloads and saves a zero byte file, or does work to download and save a 1 byte file... just can't get the whole thing!
Also note, I have to send headers b/c otherwise I get a 403 error.
Any help is greatly appreciated!
Thank you!
EDIT:
Per the comments below, here's what the urlretrieve http response is:
Date: Fri, 15 Mar 2019 23:52:44 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Set-Cookie: __cfduid=dcc5f95391fac83973cc77648c0e8c0391552693964; expires=Sat, 14-Mar-20 23:52:44 GMT; path=/; domain=.scdownloader.io; HttpOnly; Secure
X-Powered-By: PHP/5.6.36
Set-Cookie: PHPSESSID=fsnrrrtpnrav3vq5u2t9vfvrp7; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding,User-Agent
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 4b82671d38067790-LAX
I'm trying to provide the correlation id for this issue but I'm not sure how to obtain it. I assume it should be in response, is that correct? Is it the client-request-id maybe?
HTTP Response
HTTP/1.1 403 Forbidden
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: CGa9FFPZASZM+usTGvTzaOZ4zSMxhpbWh2mO9+eJZWs=
request-id: 6ddd7a86-02c9-4dcf-9932-b17afc976107
client-request-id: 50478d75-542d-4e0e-96d9-de913d632471
x-ms-dirapi-data-contract-version: 1.6
ocp-aad-session-key: some-really-long-value
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
Access-Control-Allow-Origin: *
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Duration: 782602
X-Powered-By: ASP.NET
Date: Wed, 09 Aug 2017 14:22:21 GMT
Content-Length: 139
{"odata.error":{"code":"Authorization_RequestDenied","message":{"lang":"en","value":"Insufficient privileges to complete the operation."}}}
Token Request Response
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
client-request-id: 8c500700-b75c-403a-a2c9-c6dfa27049d3
x-ms-request-id: 75627b63-fbd6-4fa8-95b5-b6a325d60900
P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"
Set-Cookie: esctx=some-value; domain=.login.microsoftonline.com; path=/; secure; HttpOnly
Set-Cookie: x-ms-gateway-slice=006; path=/; secure; HttpOnly
Set-Cookie: stsservicecookie=ests; path=/; secure; HttpOnly
X-Powered-By: ASP.NET
Date: Wed, 09 Aug 2017 18:33:33 GMT
Content-Length: 1437
{"token_type":"Bearer","expires_in":"3599","ext_expires_in":"262800","expires_on":"1502307214","not_before":"1502303314","resource":"https://graph.windows.net/","access_token":"some-token-value"}
The correlation ID (also called client-request-id) can be found in interactions with the Azure AD service.
The request immediately before this when you were asking the Azure AD endpoints for tokens will include the ID in the response.
https://login.microsoftonline.com/...
https://login.windows.net/...
I'm geting an error 'The remote server returned an error: (404) Not Found.
CloudBlockBlob blockBlob = container.GetBlockBlobReference("test.csv");
blockBlob.Properties.ContentType = "text/csv; charset=utf-8";
blockBlob.SetProperties();
The error is being thrown at SetProperties.
I have seen a few codes where they do not call SetProperties(). Does the contenttype get saved to the blob in such cases?
I did some search and found some people suggesting to check on fiddler.
The following is happening on fiddler..
/xxxevents?restype=container Result 404
/xxxevents?restype=container Result 201 Created ( Container.CreateIfNotExists called)
Now it throws an error while creating the blob.. Request and response headers provided..
404 HTTPS xxx.blob.core.windows.net /xxxevents/test.csv?comp=properties 215 application/xml waworkerhost:5500
PUT https://xxx.blob.core.windows.net/xxxevents/test.csv?comp=properties HTTP/1.1
User-Agent: WA-Storage/4.3.0 (.NET CLR 4.0.30319.18444; Win32NT 6.1.7601.65536)
x-ms-version: 2014-02-14
x-ms-blob-content-type: text/csv; charset=utf-8
x-ms-client-request-id: 2424933c-1bd7-49fd-998e-11d5499da03b
x-ms-date: Sun, 28 Sep 2014 07:16:04 GMT
Authorization: SharedKey xxx:tQ6DeUSVSq0TIaRjnVQoOgqNJIlHU5k1uay4loMeU04=
Host: xxx.blob.core.windows.net
Content-Length: 0
HTTP/1.1 404 The specified blob does not exist.
Content-Length: 215
Content-Type: application/xml
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 7845cafa-0001-0033-7d19-af2c68000000
x-ms-version: 2014-02-14
Date: Sun, 28 Sep 2014 07:15:53 GMT
Would sincerely appreciate any help
Thanks
This is expected behavior. SetBlobProperties() method can only be called on blobs which are there in your blob storage. What you would need to do is upload blob first.
Assuming you're trying to upload test.csv file from say C:\temp folder, here's what you would need to do:
CloudBlockBlob blockBlob = container.GetBlockBlobReference("test.csv");
blockBlob.Properties.ContentType = "text/csv; charset=utf-8";
blockBlob.UploadFromFile(#"C:\temp\test.csv", FileMode.Open);