I get the string from input through post option an function
Replace(string, "Č", "C")
not working, becouse function doesen't recognise 'Č' char from variable( Request.Form("folder")).
I use for loop and this function to get char from string
strChar = mid(someString,i,1)
I could use
If Asc(strChar) = -15220 Then 'Č
string = string + "C"
but doesent always work. I think becouse 'Č' some how, use more than one char if using mid() function.
Is any other solution?
Try this: Put this one on your ASP code:
Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
Response.CodePage = 65001
Response.CharSet = "UTF-8"
And in your HTML code:
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
Related
I haven't used MSXML2.ServerXMLHTTP in years and now i need to. When i use MSXML2.ServerXMLHTTP to grab a page, the page returns with broken images. I remember doing this in the past, there was a line of code i would use and the images would resolve perfectly. It was sort of like setting the base url. Does anyone know what the code would be? Here's the code i'm using:
url = "notimportant.com"
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", URL, False
objXML.Send()
xmlResponse = objXML.responseText
Set objXML = Nothing
You probably want to place a <base> tag inside the <head> so that one line of code must be the following:
xmlResponse = Replace(objXML.responseText, "<head>", "<head><base href=""http://notimportant.com/"" />", 1, 1, vbTextCompare)
Or as a more reliable way in case where the head tag is more complex and unpredictable like <head class="head etc">, you can use regular expressions to replace:
Dim Re
Set Re = New RegExp
Re.IgnoreCase = True
Re.Pattern = "<head[^>]*>"
xmlResponse = Re.Replace(objXML.responseText, "$&<base href=""http://notimportant.com/"" />")
I have this problem with SOAP that I can't seem to solve.
No matter what I try, then I keep getting this error:
500 - Internal server error. There is a problem with the resource you
are looking for, and it cannot be displayed.
When digging further down the error code I'm told there is a EOF expected error?
Hope that some of you might be able to help me
<%
On Error Resume Next
Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")
Dim strFunction
Dim strRequest
Dim strResult
Dim strName
Dim strFirstName
Dim strLastname
Dim strAddress
Dim strZipCode
Dim strCity
Dim strTelephone
Dim strTelephone2
Dim strTelephone3
Dim strTelephone4
Dim strEmail
Dim strExtFields
Dim strStdFields
Dim CampaignID
Dim Page
Page = Request.Form("Page")
CampaignID = Request.Form("CampaignID")
StrName = Request.Form("Name")
StrTelephone = Request.Form("Phone")
strRequest = ""
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"">
<Body>
<InsertNewCustomer xmlns=""http://api.ivocall.dk/ivocallservice.asmx"">
<Login>Loginname</Login>
<Password>Password</Password>
<ClientID>1323</ClientID>
<IDPassword>ag4bghsitm8gatddbpt34qjndjrbsla</IDPassword>
<CampaignID>"& campaignid &"</CampaignID>
<Name>"& StrName &"</Name>
<Firstname></Firstname>
<Lastname></Lastname>
<Address></Address>
<City></City>
<ZipCode></ZipCode>
<Telephone>"& StrTelephone &"</Telephone>
<Telephone2></Telephone2>
<Telephone3></Telephone3>
<Telephone4></Telephone4>
<email></email>
<ExtFields>landingpage="& page &"</ExtFields>
<StdFields></StdFields>
<UserName></UserName>
</InsertNewCustomer>
</Body>
</Envelope>"
objXMLHTTP.open "post", "" & "http://api.ivocall.dk/ivocallservice.asmx" & "", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=UTF-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest)
objXMLHTTP.setRequestHeader "SOAPAction", "http://www.ivocall.dk/ivocallservice/InsertNewCustomer"
'send the request and capture the result
Call objXMLHTTP.send(strRequest)
strResult = objXMLHTTP.responseText
'display the XML
response.write strResult
response.write strRequest
If Err.Number <> 0 Then
Response.Write (Err.Description)
ELSE
Response.Write ("task done")
Response.End
End If
%>
I really hope some of you can help me out her?
You use inline code-tags.
<%
They do not contain any imported namespaces.
Additionally, you seem to want to copying XML into strRequest, but you're not properly escaping it, plus VB.NET (which is what you're using, not C#) doesn't support multiline strings.
And why do you use
Server.CreateObject("Msxml2.XMLHTTP.3.0")
You can use the normal WebRequest class, instead of an ActiveX-Object. And if you want to do it client-side, you need to use JavaScript (AJAX).
If you're doing a cross-domain request, you need to use CORs (and a browser supporting CORs), or you need to write a proxy that does the request for you.
Additionally, did you try adding a web-reference to your project ?
Visual Studio will automagically download the WSDL and generate the wrapper classes. Why do you want to do it by hand ? ...
Additionally, if you want to embed code in the ASPX page, do it in a "script"-tag using runat="server":
<%# Register TagPrefix="RS" Namespace="Microsoft.ReportingServices.WebServer" Assembly="ReportingServicesWebServer" %>
<%# Page Language="C#" AutoEventWireup="true" Inherits="Microsoft.ReportingServices.WebServer.ReportViewerPage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<script type="text/C#" runat="server">
protected void SetDocumentMode()
{
if(System.Web.HttpContext.Current == null || System.Web.HttpContext.Current.Request == null || System.Web.HttpContext.Current.Request.Browser == null || System.Web.HttpContext.Current.Request.Browser.Browser == null)
// return "<null>";
return;
if (!StringComparer.OrdinalIgnoreCase.Equals(System.Web.HttpContext.Current.Request.HttpMethod, "GET"))
// return "<notget>";
return;
// fu IE 11
if(System.Web.HttpContext.Current.Request.Browser.Browser == "IE" || System.Web.HttpContext.Current.Request.Browser.Browser == "InternetExplorer")
{
if(System.Globalization.CultureInfo.InvariantCulture.CompareInfo.IndexOf(System.Convert.ToString(System.Web.HttpContext.Current.Request.QueryString), "stylesheet", System.Globalization.CompareOptions.IgnoreCase) == -1 )
{
System.Web.HttpContext.Current.Response.Write(#"<meta http-equiv='X-UA-Compatible' content='IE=5'>
");
//return "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=5\">"; // IE5-Quirks when no custom stylesheet (=not in iframe)
}
else
System.Web.HttpContext.Current.Response.Write("<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>");
// return "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">"; // Switch to Standards mode when a custom stylesheet is set(=in iframe)
}
// return "<not ie: " + System.Web.HttpContext.Current.Request.Browser.Browser + ">";
//return "";
}
</script>
[...]
<%SetDocumentMode(); %>
Are you actually using ASP instead of ASP.NET ?
I am new in classic asp.
I added this two line on the top of document
<%# Language=VBScript CODEPAGE=950 %>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
And I written some simple code
Dim str0
str0 = Request.ServerVariables("QUERY_STRING")
Response.write("Orginal string :"&str0)
And the query string contain the Chinese
http://www.mytest.com/test.asp?as=更
The output of different browser
Chrome:
Orginal string :as=%E6%9B%B4
IE:
Orginal string :as=更
May I know how can I solve this problem? Thanks
I have a website where google pics up some links on my site and sends throught the following URL
http://www.globalpropertyonline.net/test.asp?town=gand%EDa
I have one of the URLDecode Functions I found on the net to Decode the %ED
However, this seems not to be working the correct way.
The %ED should be this : í
So when I Decode it the word should be gandía
But instead I get the following word : gand�a
On the page where google gets the link, it is displayed correctly as gandía but it prompts me in webmaster tools that the following link has a error 500 and this is because when I try to take this name and sends it to the MYSQL query it crash with error 500 but if I would have had gandía then it worked !
So, my main problem is that I am getting the %ED sent as URLEncode as it seems and I want to Decode it before I send it to my database query.
In my ASP Page I am using UTF-8 Encodeing as follows.
<%# CodePage=65001 Language="VBScript"%>
<%
Response.CodePage = 65001
Response.CharSet = "utf-8"
This is the Code I am using to Decode it but instead if getting the gandía I get this : gand�a
any help will be much apreciated
<%# CodePage=65001 Language="VBScript"%>
<%
Response.CodePage = 65001
Response.CharSet = "utf-8"
MyTown = Request("town")
response.write URLDecode(MyTown)
Function URLDecode(str)
str = Replace(str, "+", " ")
For i = 1 To Len(str)
sT = Mid(str, i, 1)
If sT = "%" Then
If i+2 < Len(str) Then
sR = sR & _
Chr(CLng("&H" & Mid(str, i+1, 2)))
i = i+2
End If
Else
sR = sR & sT
End If
Next
URLDecode = sR
End Function
%>
It looks like you have not defined the page as UTF-8 client-side. You can this by adding this inside <head></head>:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
I am sending a file from ASP.NET Page to the browser. To properly send a filename I am adding a header:
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
The problem is that when file contains white spaces (e.g. "abc def") browser receives only "abc" part of the filename. I have tried with: Server.HtmlEncode but it didn't help.
Do you have any idea how to solve this problem?
PK
Put the file name in quotes:-
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
Don't UrlEncode. This is not the right way to escape a value for use in an HTTP structured header parameter. It only works in IE due to that browser's buggy handling, and even then not reliably.
For a space you can use a quoted-string as suggested by Anthony (+1). But the dirty truth of Content-Disposition is that there is no reliable, supported escaping scheme that can be used to put arbitrary characters such as ;, " or Unicode characters in the filename parameter. The only approach that works reliably cross-browser is to drop the filename parameter completely and put the desired filename in the URI as a trailing, UTF-8+URL-encoded path part.
See this answer for some background.
Filename with special symbols(e.g: space; # # ! $ ) or Non-Unicode characters either cannot be supported by some browsers or cause incorrect filename in client machine.
Here is an article by a Chinese called chanext, he gave a perfect way to solve this problem:
this article gave a sample code(written with c#) to show how to get perfect solution to this problem in the all four popular browsers (IE; Opera; Firefox and Chrome)
the filename "Microsoft.Asp.Net.doc" and "F ile;;!#%#^&y.doc" can both be output correctly using the way the author provided in this article.
http://ciznx.com/post/aspnetstreamdownloaddisplaynonunicodespacechar.aspx
Based on the code referenced by #chanext I cleaned it up and put it into a single extension method. Hope this can help someone.
Partial Class Uploader
Inherits Page
Private Sub UploadFile()
Dim sFileName As String
Dim oPdf As MigraDoc.Rendering.PdfDocumentRenderer
sFileName = "File Name With Spaces #22.pdf"
With Me.Request.Browser
If .Browser = "InternetExplorer" OrElse .Browser = "IE" Then
sFileName = sFileName.EncodeForIE
Else
sFileName = String.Format("""{0}""", sFileName)
End If
End With
oPdf = New MigraDoc.Rendering.PdfDocumentRenderer
oPdf.Document = FileFactory.CreatePdf()
oPdf.RenderDocument()
Using oStream As New MemoryStream
oPdf.Save(oStream, False)
Me.Response.Clear()
Me.Response.ContentType = "application/pdf"
Me.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", sFileName))
Me.Response.AddHeader("content-length", oStream.Length)
Me.Response.BinaryWrite(oStream.ToArray)
End Using
Me.Response.Flush()
Me.Response.End()
End Sub
End Class
Public Module StringExtensions
<Extension()>
Public Function EncodeForIE(Url As String) As String
Dim _
sReservedChars,
sEncodedString As String
sReservedChars = "$-_.+!*'(),#=&"
With New StringBuilder
Url.ToList.ForEach(Sub(C)
If Char.IsLetterOrDigit(C) OrElse sReservedChars.Contains(C) Then
.Append(C)
Else
With New StringBuilder
C.ToBytes.ToList.ForEach(Sub(B)
.AppendFormat("%{0}", Convert.ToString(B, 16))
End Sub)
sEncodedString = .ToString
End With
.Append(sEncodedString)
End If
End Sub)
Return .ToString
End With
End Function
<Extension()>
Public Function ToBytes(Chr As Char) As Byte()
Return Encoding.UTF8.GetBytes(Chr.ToString)
End Function
End Module