Example Xojo.net.httpsocket with a file

I’ve got many examples for the new httpsocket on IOS but no one with the import of a file.
DocumentSocket.GetDocument(urlDoc, outputFile)

I have a method GetDocument in the httpsocket which is:

// Call to get document Self.Send("GET", urlDoc, outputFile)

The content of urlDoc is a document file that we can access in my internal network:

http://192.168.0.51/ecw/gestproj/documentation/Blade Repair Report - WEC11 - Axe 1-2.pdf

I always get the message:
Request url is not well-formed.

I do not know what to do with it.

Edit (Paul): Fixed code formatting. See Post Formatting Tips.

You probably need to URLEncode the URL.
I’m not sure if there’s a function for it in the new framework.

The spaces in your URL might be throwing this error.

That should work :

Dim urlDoc as Text = EncodeURLComponent("http://192.168.0.51/ecw/gestproj/documentation/Blade Repair Report - WEC11 - Axe 1-2.pdf") Self.Send("GET", urlDoc, outputFile)

BTW, when you post code, select it and click the code icon above the editor. It makes it nicely legible.

EncodeURLComponent returns a string and is not part of the new framework I thought?
The developer.xojo.com reference links to the old framework page.

Indeed. I hate this bowl of mixed stuff on developer.xojo.com. It was way easier when everything there was iOS.

Dim urlDoc as Text = "http://192.168.0.51/ecw/gestproj/documentation/Blade Repair Report - WEC11 - Axe 1-2.pdf" urlDoc = urlDoc.ReplaceAll(" ","\\ ") Self.Send("GET", urlDoc, outputFile)

Still not quite right I don’t think. In a URL spaces are escaped with hex (%26) rather than backslash. For safety I’d go about using EncodeURLComponent and converting that to Text.

[code]dim sTemp as String = EncodeURLComponent(kDocURL)
sTemp = DefineEncoding(sTemp, Encodings.UTF8)
dim stxtURLDoc as Text = sTemp.ToText

self.Send(“GET”, stxtURLDoc, outputFile)
[/code]

Edit:
Oh but wait… iOS doesn’t have the old framework.
Shit sorry.

For now just ReplaceAll the spaces with %26

There is no EncodeURLComponent for the new framework (and thus iOS) yet. In the meantime, you can use a Declare like this:

[code]Declare Function CFURLCreateStringByAddingPercentEscapes Lib “Foundation” (allocator As Ptr, origString As CFStringRef, charactersToLeaveUnescaped As CFStringRef, legalURLCharactersToBeEscaped As CFStringRef, encoding As UInt32) As CFStringRef

Dim url As Text = “http://192.168.0.51/ecw/gestproj/documentation/Blade Repair Report - WEC11 - Axe 1-2.pdf”

Dim encodedURL As Text
encodedURL = CFURLCreateStringByAddingPercentEscapes(Nil, url, Nil, Nil, &h08000100)[/code]

encodedURL is now:

http://192.168.0.51/ecw/gestproj/documentation/Blade%20Repair%20Report%20-%20WEC11%20-%20Axe%201-2.pdf

Reference: EncodeURLComponent

Norman posted a plain Xojo implementation a while ago: https://forum.xojo.com/33053-encodeurlcomponent-equivalent/p1#p270929

[quote=315572:@Tim Parnell]Still not quite right I don’t think. In a URL spaces are escaped with hex (%26) rather than backslash. For safety I’d go about using EncodeURLComponent and converting that to Text.

[code]dim sTemp as String = EncodeURLComponent(kDocURL)
sTemp = DefineEncoding(sTemp, Encodings.UTF8)
dim stxtURLDoc as Text = sTemp.ToText

self.Send(“GET”, stxtURLDoc, outputFile)
[/code]

Edit:
Oh but wait… iOS doesn’t have the old framework.
Shit sorry.

For now just ReplaceAll the spaces with %26[/quote]
That should be %20. %26 makes a &

Nobody’s right tonight!