Basket API not work

59 views
Skip to first unread message

Cary

unread,
May 14, 2012, 11:13:14 PM5/14/12
to build-kiva
Hi,

I write an application using C#, I am encountering using basket API,
below is the code I wrote, please help me to figure out where the
problem is, thanks.

JsonObject jsonObject = new JsonObject();
jsonObject.Add("id",
JsonValue.CreateNumberValue(Convert.ToDouble(item.UniqueId)));
jsonObject.Add("amount", JsonValue.CreateNumberValue(25));
String jsonString = jsonObject.Stringify();
HttpWebRequest request = HttpWebRequest.Create("http://
www.kiva.org/basket/set") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json";
Stream dataStream = await request.GetRequestStreamAsync();
StreamWriter writer = new StreamWriter(dataStream);
await writer.WriteAsync(jsonString);
writer.Dispose();

after above code finished, I will open the IE to let the app user
browse the loans they chose, and check out through IE. below is code
of open IE.

await Windows.System.Launcher.LaunchUriAsync(new
Uri("http://www.kiva.org/basket"));

Cary

unread,
May 15, 2012, 1:58:16 AM5/15/12
to build-kiva
Here is the network package I got from Winshark

POST http://www.kiva.org/basket/set HTTP/1.1
Content-Type: text/plain; charset=utf-8
Host: www.kiva.org
Content-Length: 25
Expect: 100-continue

HTTP/1.1 100 Continue

{"id":425356,"amount":25}HTTP/1.1 302 Found
Date: Tue, 15 May 2012 05:41:20 GMT
Server: Apache
Vary: Host,Accept-Encoding
P3P: CP="HONK"
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
Location: http://www.kiva.org/error.html?url=basket%2Fset&status=404
Content-Type: text/html
Via: 1.1
Content-Length: 0
Proxy-Connection: Keep-AliveConnection: Keep-Alive
Set-Cookie: kv=3ep7jo3kcj1ah1ep1f24j4tt2pbcv6h6; path=/; HttpOnly

GET http://www.kiva.org/error.html?url=basket%2Fset&status=404 HTTP/
1.1
Content-Type: text/plain; charset=utf-8
Host: www.kiva.org
Cookie: kv=3ep7jo3kcj1ah1ep1f24j4tt2pbcv6h6

HTTP/1.1 404 Not Found
Date: Tue, 15 May 2012 05:41:21 GMT
Server: Apache
Vary: Host,Accept-Encoding
Last-Modified: Mon, 07 May 2012 21:33:48 GMT
Accept-Ranges: bytes
Content-Type: text/html
Via: 1.1
Proxy-Connection: Keep-Alive
Connection: Keep-Alive

On 5月15日, 上午11時13分, Cary <boboc...@gmail.com> wrote:
> Hi,
>
> I write an application using C#, I am encountering using basket API,
> below is the code I wrote, please help me to figure out where the
> problem is, thanks.
>
>             JsonObject jsonObject = new JsonObject();
>             jsonObject.Add("id",
> JsonValue.CreateNumberValue(Convert.ToDouble(item.UniqueId)));
>             jsonObject.Add("amount", JsonValue.CreateNumberValue(25));
>             String jsonString = jsonObject.Stringify();
>             HttpWebRequest request = HttpWebRequest.Create("http://www.kiva.org/basket/set") as HttpWebRequest;

Kevin O'Brien

unread,
May 15, 2012, 2:06:51 AM5/15/12
to build...@googlegroups.com
I'm not really sure I understand what you are trying to accomplish, but granted I'm pretty limited with my C#. 

Could you explain in pseudo-code what you are trying to do? 

Is your goal to send people to the Kiva basket with a POST request to fill in the loans to acquire?

-k

--
You received this message because you are subscribed to the Google Groups "build-kiva" group.
To post to this group, send email to build...@googlegroups.com.
To unsubscribe from this group, send email to build-kiva+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/build-kiva?hl=en.


Noah Balmer

unread,
May 15, 2012, 2:23:52 AM5/15/12
to build...@googlegroups.com
You have to set a "loans" or "donation" POST parameter for the basket/set url to work.  If you don't, it will give you a 404.

Cary

unread,
May 15, 2012, 3:52:19 AM5/15/12
to build-kiva
I have add the loans to the structure, but still get 404 error, please
see the interception information below :

POST http://www.kiva.org/basket/set HTTP/1.1
Content-Type: text/plain; charset=utf-8
Host: www.kiva.org
Content-Length: 63
Expect: 100-continue

HTTP/1.1 100 Continue{"loans":[{"id":425880,"amount":25},{"id":
106957,"amount":30}]}HTTP/1.1 302
FoundDate: Tue, 15 May 2012 07:47:52 GMT
Server: Apache
Vary: Host,Accept-Encoding
P3P: CP="HONK"
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-cacheLocation: http://www.kiva.org/error.html?url=basket%2Fset&status=404
Content-Type: text/html
Via: 1.1 f
Content-Length: 0
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Set-Cookie: kv=ql1ebsgens8b9sjcp471ugjoac8i6u3k; path=/; HttpOnly

GET http://www.kiva.org/error.html?url=basket%2Fset&status=404 HTTP/
1.1
Content-Type: text/plain; charset=utf-8
Host: www.kiva.org
Cookie: kv=ql1ebsgens8b9sjcp471ugjoac8i6u3k

On 5月15日, 下午2時23分, Noah Balmer <n...@kiva.org> wrote:
> You have to set a "loans" or "donation" POST parameter for the basket/set
> url to work.  If you don't, it will give you a 404.
>
>
>
>
>
>
>
> On Mon, May 14, 2012 at 11:06 PM, Kevin O'Brien <ke...@kiva.org> wrote:
> > I'm not really sure I understand what you are trying to accomplish, but
> > granted I'm pretty limited with my C#.
>
> > Could you explain in pseudo-code what you are trying to do?
>
> > Is your goal to send people to the Kiva basket with a POST request to fill
> > in the loans to acquire?
>
> > -k
>
> > On Mon, May 14, 2012 at 10:58 PM, Cary <boboc...@gmail.com> wrote:
>
> >> Here is the network package I got from Winshark
>
> >> POSThttp://www.kiva.org/basket/setHTTP/1.1
> >> Content-Type: text/plain; charset=utf-8
> >> Host:www.kiva.org
> >> Content-Length: 25
> >> Expect: 100-continue
>
> >> HTTP/1.1 100 Continue
>
> >> {"id":425356,"amount":25}HTTP/1.1 302 Found
> >> Date: Tue, 15 May 2012 05:41:20 GMT
> >> Server: Apache
> >> Vary: Host,Accept-Encoding
> >> P3P: CP="HONK"
> >> 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
> >> Location:http://www.kiva.org/error.html?url=basket%2Fset&status=404
> >> Content-Type<http://www.kiva.org/error.html?url=basket%2Fset&status=404Content-Type>:

Cary

unread,
May 15, 2012, 7:03:48 AM5/15/12
to build-kiva
Here is the intercept of another testing below :

POST http://www.kiva.org/basket/set?loans=[%7B%22id%22:425355,%22amount%22:25%7D,%7B%22id%22:106957,%22amount%22:30%7D]
HTTP/1.1

Host: www.kiva.org




HTTP/1.1 302 Found

Date: Tue, 15 May 2012 10:57:11 GMT

Server: Apache

Vary: Host,Accept-Encoding

P3P: CP="HONK"

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

Location: http://www.kiva.org/error.html?url=basket%2Fset&status=404

Content-Type: text/html

Via: 1.1

Content-Length: 0

Proxy-Connection: Keep-Alive

Connection: Keep-Alive

Set-Cookie: kv=6a5o29bv2lcfmrb0grl1539p9f1b05sj; path=/; HttpOnly




POST http://www.kiva.org/error.html?url=basket%2Fset&status=404 HTTP/
1.1

Host: www.kiva.org




HTTP/1.1 404 Not Found

Date: Tue, 15 May 2012 10:57:12 GMT

Server: Apache

Vary: Host,Accept-Encoding

Last-Modified: Mon, 07 May 2012 21:33:48 GMT

Accept-Ranges: bytes

Content-Type: text/html

Via: 1.1

Content-Length: 9800

Proxy-Connection: Keep-Alive

Connection: Keep-Alive

On 5月15日, 下午3時52分, Cary <boboc...@gmail.com> wrote:
> I have add the loans to the structure, but still get 404 error, please
> see the interception information below :
>
> POSThttp://www.kiva.org/basket/setHTTP/1.1
> Content-Type: text/plain; charset=utf-8
> Host:www.kiva.org
> Content-Length: 63
> Expect: 100-continue
>
> HTTP/1.1 100 Continue{"loans":[{"id":425880,"amount":25},{"id":
> 106957,"amount":30}]}HTTP/1.1 302
> FoundDate: Tue, 15 May 2012 07:47:52 GMT
> Server: Apache
> Vary: Host,Accept-Encoding
> P3P: CP="HONK"
> 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-cacheLocation:http://www.kiva.org/error.html?url=basket%2Fset&status=404
> Content-Type: text/html
> Via: 1.1 f
> Content-Length: 0
> Proxy-Connection: Keep-Alive
> Connection: Keep-Alive
> Set-Cookie: kv=ql1ebsgens8b9sjcp471ugjoac8i6u3k; path=/; HttpOnly
>

Paul Ericksen

unread,
May 15, 2012, 1:49:45 PM5/15/12
to build...@googlegroups.com
This works:

<form method="post" action="http://www.kiva.org/basket/set" id="jsonform" > 

  <input name="loans" value='[{"amount":25,"id":420585},{"amount":25,"id":420586}]' type="hidden" /> 

  <input name="donation" value="0.00" type="hidden"/> 

  <input name="app_id" value="org.kivabank" type="hidden" /> 

  <input type="submit" value="Transfer loans to Kiva's basket" />

</form> 


I believe it only works for form posts.
Sent from my computer. No excuses for misspellings or missing words.

Noah Balmer

unread,
May 15, 2012, 8:30:05 PM5/15/12
to build...@googlegroups.com
Here's a POST HTTP stream that I got when submitting Paul's working form in Firefox.  You want a body on your POST request that looks about like this. 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: <redacted>
Content-Type: application/x-www-form-urlencoded
Content-Length: 135

loans=%5B%7B%22amount%22%3A25%2C%22id%22%3A420585%7D%2C%7B%22amount%22%3A25%2C%22id%22%3A420586%7D%5D&donation=0.00&app_id=org.kivabank


And the response - a redirect to the basket page with appropriate basket contents:
HTTP/1.1 302 Found
Date: Wed, 16 May 2012 00:15:45 GMT
Server: Apache
Vary: Host,Accept-Encoding
P3P: CP="HONK"
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
Content-Encoding: gzip
Content-Length: 20
Connection: close
Content-Type: text/html

....................
Reply all
Reply to author
Forward
0 new messages