question

newuser-8f980dc1-857e-46b8-ab86-b1b1d4803d49 avatar image

I m trying to integrate Alexa Voice Service in my Application . While doing API Post to Alexa Server and Get response i m facing server error "Network connection is lost" even though i have network connectivity .??

AVS - IOS - OBJECTIVE C - SAMPLE ? AND ISSUES

alexa voice service
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

elstryan@Amazon avatar image
elstryan@Amazon answered

Hi,

We don't have an Objective-C sample.

In the past when experimenting with Objective-C I've seen this error come up with a not fully formed request.

Have you verified that you are adding the boundary term(s), Content-Type, and Content-Disposition as specified here:

https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/avs-http2-requests

Alternatively you could post your code that is making requests to Alexa Voice Service that we could look at the code and see if we can spot anything.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-507f85b5-2dac-4f24-8eca-e95f2a5ff3fa avatar image
newuser-507f85b5-2dac-4f24-8eca-e95f2a5ff3fa answered

My Sample Request is as below

//boundary value

uuid = [[UIDevicecurrentDevice] identifierForVendor];

boundryUUID = uuid.UUIDString;

NSString * contentType = [NSStringstringWithFormat:@"multipart/form-data; boundary=%@",boundryUUID];

NSString * avsToken = [[NSUserDefaultsstandardUserDefaults]objectForKey:AccessToken];

[request setValue:[NSStringstringWithFormat:@"Bearer %@",avsToken] forHTTPHeaderField:@"Authorization"];

[request setValue:contentType forHTTPHeaderField:@"Content-Type"];

// end of request formation

// message body part

NSMutableData * bodyData = [[NSMutableDataalloc]init];

[bodyData appendData:[[NSStringstringWithFormat:@"--%@\r\n",boundryUUID]dataUsingEncoding:NSUTF8StringEncoding]];

[bodyData appendData:[[NSStringstringWithFormat:@"Content-Disposition: form-data; name=\"metadata\"\r\n"]dataUsingEncoding:NSUTF8StringEncoding]];

[bodyData appendData:[[NSStringstringWithFormat:@"Content-Type: application/json; charset=UTF-8\r\n\r\n"]dataUsingEncoding:NSUTF8StringEncoding]];

[bodyData appendData:[[selfcreateContext] dataUsingEncoding:NSUTF8StringEncoding]];

[bodyData appendData:[[NSStringstringWithFormat:@"\r\n\r\n"]dataUsingEncoding:NSUTF8StringEncoding]];

[bodyData appendData:[[NSStringstringWithFormat:@"--%@\r\n",boundryUUID]dataUsingEncoding:NSUTF8StringEncoding]];

[bodyData appendData:[[NSStringstringWithFormat:@"Content-Disposition: form-data; name=\"audio\"\r\n"]dataUsingEncoding:NSUTF8StringEncoding]];

[bodyData appendData:[[NSStringstringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"]dataUsingEncoding:NSUTF8StringEncoding]];

[bodyData appendData:audioData];

[bodyData appendData:[[NSStringstringWithFormat:@"\r\n"]dataUsingEncoding:NSUTF8StringEncoding]];

[bodyData appendData:[[NSStringstringWithFormat:@"--%@\r\n",boundryUUID]dataUsingEncoding:NSUTF8StringEncoding]];

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sanjay@Amazon avatar image
Sanjay@Amazon answered

It's a bit hard to see what this generates just by looking at the code. Could you possibly post a sample request that the code above generates?

Alternatively, if you have an x-amzn-requestid, we can dig into what's going on from the server side of things.

Thanks,

Sanjay

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.