# Sugar HTTP

**URL:** https://talk.remobjects.com/t/sugar-http/6257
**Category:** Silver
**Created:** [May 26, 2015, 5:18pm UTC](https://talk.remobjects.com/t/sugar-http/6257 "2015-05-26T17:18:44Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 26, 2015, 3:51pm UTC](https://talk.remobjects.com/t/sugar-http/6257/1 "2015-05-26T15:51:38Z")

</div>

@mh I’m struggling with using Http in Sugar ☹ I am unable to get response.Content. How can I see its value in the debugger? When I use it in the Android project, It always gets passed as null. Do you have anything running in swift that confirms if Http works in Sugar?

```
let completion1: HttpResponseBlock<String!>! = { response in {
		//NSLog(response.Content)
		//completion(response.Content)
		completion(response.Content)
		}
	}
	let url = Url("http://httpbin.org/get")
	Http.DownloadStringAsync(url, Encoding.UTF8, completion1)
```

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [May 26, 2015, 5:21pm UTC](https://talk.remobjects.com/t/sugar-http/6257/2 "2015-05-26T17:21:59Z")

</div>

Hm. for one, this code doesn’t compile. The extra set of curlies after “`in`” needs to go away, and `completion` isn’t defined. Can you post a full compiling snippet/project?

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 26, 2015, 5:31pm UTC](https://talk.remobjects.com/t/sugar-http/6257/3 "2015-05-26T17:31:48Z")

</div>

> [@mh](#):
>
> The extra set of curlies after “in” needs to go away,

Okay so I’ve removed the extra curlies but now I always get response to the an “unknown value” in the debugger.  
Btw I noticed that whatever I pass to the completion (even a static string) it always shows up as “Unknown Value” in the debugger. Could it be that the debugger is buggy?

Here’s the full code. Can you figure out what’s wrong?

```
import Sugar

public class SKNetwork {

public class func performNetworkRequestWithUri(uriString: Sugar.String, withCompletion completion: (response: Sugar.String?) -> ()) {
	
	//let url = Url(uriString: uriString)
	let completion1: HttpResponseBlock<String!>! = { response in {
		//NSLog(response.Content)
		//completion(response.Content)

		completion(response.Content)
		}
	}
	
	let url = Url("http://httpbin.org/get")
	//let url = Url("http://m090009.com")
	Http.DownloadStringAsync(url, Encoding.UTF8, completion1)
	
}
}

```

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 27, 2015, 9:46am UTC](https://talk.remobjects.com/t/sugar-http/6257/4 "2015-05-27T09:46:15Z")

</div>

@mh any luck with this?

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 27, 2015, 12:05pm UTC](https://talk.remobjects.com/t/sugar-http/6257/5 "2015-05-27T12:05:53Z")

</div>

you want to add this to your manifest (under Properties in the IDE):

```xml

  <uses-permission android:name="android.permission.INTERNET" />

```

After that I get a proper response. I did notice 1 of the types being wrong, so I’ll post a bug fir that.

If you put a breakpoint on completion(response.Content) and expand response you can see:

```auto
exception: java.lang.SecurityException: Permission denied (missing INTERNET permission?)

```

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [May 27, 2015, 12:06pm UTC](https://talk.remobjects.com/t/sugar-http/6257/6 "2015-05-27T12:06:34Z")

</div>

Thanks, logged as bugs://72111

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 27, 2015, 2:44pm UTC](https://talk.remobjects.com/t/sugar-http/6257/7 "2015-05-27T14:44:28Z")

</div>

> [@ck](#):
>
> you want to add this to your manifest (under Properties in the IDE):

Awesome started a new test project and forgot to do this! It’s working perfectly on Android.

@ck@mh As for iOS, I’m getting this compiler error. Just to get it right, I copied the .a files from the bin \> Release into the Xcode project (and added them to link binaries with libs) also added the -Objc linker flag. Since I’m using a swift project I also added the Bridging-Header.h and imported the header. After doing this I get this error.

![](https://talk.remobjects.com/uploads/default/original/8/9/89bd10acaaccd41bb33e415f47f4ed7007361dce.png)

Strangely, if I comment the import statement in the bridging header, I get a different error:

![](https://talk.remobjects.com/uploads/default/original/f/0/f0aebb870bfd587631053ecba5febb3fd33ddff2.png)

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 27, 2015, 2:46pm UTC](https://talk.remobjects.com/t/sugar-http/6257/8 "2015-05-27T14:46:38Z")

</div>

You want to add a ref to Sugar.a too for the linker errors. As for the unknowntype, can you show the exact types you ended up with for SKFunctionals, so I can fix the header generator?

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 27, 2015, 3:00pm UTC](https://talk.remobjects.com/t/sugar-http/6257/9 "2015-05-27T15:00:44Z")

</div>

> [@ck](#):
>
> You want to add a ref to Sugar.a too for the linker errors

@ck where can I get Sugar.a from ?

> [@ck](#):
>
> As for the unknowntype, can you show the exact types you ended up with for SKFunctionals, so I can fix the header generator?

This is the SKFunctionals Class

```
public class SKFunctionals {
public func bind<A,B> (a: A?, f: A->B) -> B? {
    if let x = a {
		 return f(x)
	 }
	 else {
	     return nil
	 }
}
}

```

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [May 27, 2015, 3:01pm UTC](https://talk.remobjects.com/t/sugar-http/6257/10 "2015-05-27T15:01:40Z")

</div>

Thanks, logged as bugs://72116

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 27, 2015, 3:03pm UTC](https://talk.remobjects.com/t/sugar-http/6257/11 "2015-05-27T15:03:10Z")

</div>

libSugar.a is next to libSugar.fx, depending on if you use fire it’s inside the Fire.app, else it’s in Program Files (x86)\Elements\Nougat. Odds are though, there’s a libSugar.a next to your existing project output dir already.

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 27, 2015, 3:13pm UTC](https://talk.remobjects.com/t/sugar-http/6257/12 "2015-05-27T15:13:12Z")

</div>

@ck okay so I found the libSugar.a in the Fire.app, I selected the libSugar from the iOS folder but after doing so, it tells me that its skipping the file due to unmatched architecture this is the exact warning

```
ld: warning: ignoring file /Users/salmanhasratkhan/Desktop/test/test/test/libSugar.a, missing required architecture x86_64 in file /Users/salmanhasratkhan/Desktop/test/test/test/libSugar.a (2 slices)

```

Should I be using the OS X libSugar.a ?

> [@ck](#):
>
> Odds are though, there’s a libSugar.a next to your existing project output dir already.

There’s no libSugar.a next to my existing project maybe this could be a feature request to add it to the bin folder of the class library?

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 27, 2015, 3:20pm UTC](https://talk.remobjects.com/t/sugar-http/6257/13 "2015-05-27T15:20:21Z")

</div>

@ck Okay so I tried using the libSugar.a from the OS X folder and now its not skipping the file, but I have 45 errors.  
 ![](https://talk.remobjects.com/uploads/default/original/3/2/3222cdb9d7d64bf9f7f786bd98f792cd119c432a.png)

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 27, 2015, 5:50pm UTC](https://talk.remobjects.com/t/sugar-http/6257/14 "2015-05-27T17:50:22Z")

</div>

That’s libxml2 (I think just a linker param:: -l xml2)

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 27, 2015, 8:36pm UTC](https://talk.remobjects.com/t/sugar-http/6257/15 "2015-05-27T20:36:13Z")

</div>

@mh @ck One question though, even though I created a static library for iOS in Fire, why does it compile as an OS X library? even when I added the libSugar.a, I had to add the OS X version as clang would just skip the iOS version of libSugar.a. Is this a bug or is it expected behaviour?

@ck after adding the linker params, I’ve also added the libNougat.a, and now the errors are reduced to 2 only. Some protocol is referenced that doesn’t work  
 ![](https://talk.remobjects.com/uploads/default/original/6/1/614b00f19f256c19c795b0e314f7ee837ee6af02.png)

~~@ck I've added the linker param, but now its giving me 5 errors, some protocol and boxed char are not found. Just to be sure, so far I've just added the compiled static library from Fire and the libSugar.a. Should I be adding something else?~~

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 27, 2015, 9:08pm UTC](https://talk.remobjects.com/t/sugar-http/6257/16 "2015-05-27T21:08:13Z")

</div>

> [@Salman](#):
>
> @mh @ck One question though, even though I created a static library for iOS in Fire, why does it compile as an OS X library? even when I added the libSugar.a, I had to add the OS X version as clang would just skip the iOS version of libSugar.a. Is this a bug or is it expected behaviour?

i think both issues are related to a mismatch somewhere, like Fire compiling iPhoneSimulator (which matches OSX in platform), and you compiling OSX or reverse.

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 28, 2015, 11:16am UTC](https://talk.remobjects.com/t/sugar-http/6257/17 "2015-05-28T11:16:33Z")

</div>

> [@ck](#):
>
> i think both issues are related to a mismatch somewhere, like Fire compiling iPhoneSimulator

Can I send you the project and maybe you can look at it ?

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [May 28, 2015, 1:41pm UTC](https://talk.remobjects.com/t/sugar-http/6257/18 "2015-05-28T13:41:37Z")

</div>

Please, yes. it definitely sounds like its getting mixed up between OS X and iOS, somehow.

> [@Salman](#):
>
> Can I send you the project and maybe you can look at it ?

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [June 9, 2015, 9:20pm UTC](https://talk.remobjects.com/t/sugar-http/6257/19 "2015-06-09T21:20:22Z")

</div>

bugs://72116 got closed with status fixed.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [November 16, 2015, 8:08am UTC](https://talk.remobjects.com/t/sugar-http/6257/20 "2015-11-16T08:08:52Z")

</div>

bugs://72111 got closed with status nochangereq.
