@@ -4,7 +4,7 @@ import * as application from 'tns-core-modules/application'
44import { HttpRequestOptions , Headers , HttpResponse } from 'tns-core-modules/http'
55import { isDefined , isNullOrUndefined , isObject } from 'tns-core-modules/utils/types'
66import * as Https from './https.common'
7- import { HttpsResponse } from "./https.common" ;
7+ import { HttpsRequestObject , HttpsResponse } from "./https.common" ;
88
99
1010interface Ipolicies {
@@ -49,18 +49,36 @@ export function request(options: Https.HttpsRequestOptions): Promise<Https.Https
4949 return new Promise ( function ( resolve , reject ) {
5050 try {
5151
52- let request = NSMutableURLRequest . requestWithURL (
53- NSURL . URLWithString ( options . url ) ) ;
52+
53+ let url ;
54+ const params = < HttpsRequestObject > options . params ;
55+ if ( params ) {
56+
57+ url = NSURLComponents . componentsWithString ( options . url ) ;
58+
59+ for ( const paramsKey in params ) {
60+ const value = params [ paramsKey ] ;
61+ const queryItem = NSURLQueryItem . queryItemWithNameValue ( paramsKey , String ( value ) ) ;
62+ url . queryItems . arrayByAddingObject ( queryItem ) ;
63+ }
64+ } else {
65+ url = NSURL . URLWithString ( options . url ) ;
66+ }
67+
68+ let request = NSMutableURLRequest . requestWithURL ( url ) ;
69+
5470 request . HTTPMethod = options . method ;
5571
56- let headers = options . headers ;
72+ const headers = options . headers ;
5773 if ( headers ) {
5874 Object . keys ( headers ) . forEach ( function ( key ) {
5975 request . setValueForHTTPHeaderField ( headers [ key ] as any , key ) ;
6076 } ) ;
6177 }
6278
63- let jsonString = NSString . stringWithString ( JSON . stringify ( options . body ) ) ;
79+ const body = options && options . body ? options . body : null ;
80+
81+ let jsonString = NSString . stringWithString ( JSON . stringify ( body ) ) ;
6482 request . HTTPBody = jsonString . dataUsingEncoding ( NSUTF8StringEncoding ) ;
6583
6684 let manager = AFHTTPSessionManager . manager ( ) ;
@@ -90,7 +108,8 @@ export function request(options: Https.HttpsRequestOptions): Promise<Https.Https
90108 }
91109
92110 resolve ( < HttpsResponse > {
93- content : content
111+ content : content ,
112+ statusCode : response . statusCode
94113 } ) ;
95114 }
96115 } ) . resume ( ) ;
0 commit comments