AFNetworkingメモ
今日最新バージョンのAFNetworkingに穴をあけられて、CocoaPodsは引き延ばしてバージョン番号をプラスしていないで、最新バージョンのを引き延ばして、バージョンはPost JSONがある時前にパラメータの最も前に多く出ます"="を受け取ってサービス側のjsonが解析できないことを招いて、Releaseバージョンに下がった後に、すべて正常です.簡単な例を書いて、記録します.
iOSエンド
サーバC#切断処理インタフェース
iOSエンド
/**
* gps
*/
-(void)postLocation:(BMKUserLocation *)userLocation{
//_locService
//BMKUserLocation *userLocation = _locService.userLocation;
if (userLocation != nil && userLocation.location.coordinate.latitude != 0) {
// http://192.168.0.115:9999/UploadServices/SaveLocation
// SDF E6E9BD22-F909-4588-9EB7-B80776946519
// {
// "AWL_LAN":"123123",
// "AWL_LON":"111",
// "U_ID":"1"
// }
__block NSMutableDictionary *dic = [NSMutableDictionary new];
[dic setObject:[NSString stringWithFormat:@"%f" , userLocation.location.coordinate.latitude] forKey:@"AWL_LAN"];
[dic setObject:[NSString stringWithFormat:@"%f" , userLocation.location.coordinate.longitude] forKey:@"AWL_LON"];
[dic setObject:@"1" forKey:@"U_ID"];
// NSString *jsonString = nil;
// if ([NSJSONSerialization isValidJSONObject:dic])
// {
// NSError *error;
// NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error];
// jsonString =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
// NSLog(@"json data:%@",jsonString);
// }
NSString *url = @"http://192.168.0.115:9999/UploadServices/SaveLocation";
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer new];
// manager.responseSerializer = [AFJSONResponseSerializer new];// JSON
// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];// text/html
manager.requestSerializer = [AFJSONRequestSerializer serializer];// JSON
[manager.requestSerializer setValue:@"E6E9BD22-F909-4588-9EB7-B80776946519" forHTTPHeaderField:@"SDF"];
[manager POST:url parameters:dic success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"result: %@", result );
} failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
NSLog(@"Error: %@", error);
}];
}
}
サーバC#切断処理インタフェース
[WebInvoke(UriTemplate = "SaveLocation", Method = "POST"), Description(" ")]
public string SaveLocation(Stream source) {
//StreamReader reader = new StreamReader(source);
//string text = reader.ReadToEnd();
//text = HttpUtility.UrlDecode(text);
// URL
string serviceUrl = "UploadServices/SaveLocation";
//
DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(APP_WATER_LOCATION));
APP_WATER_LOCATION location = (APP_WATER_LOCATION)json.ReadObject(source);
if (location == null)
{
return "false";
}
location.AWL_DATE = DateTime.Now;
AppWaterLocationService.Instance.Add(location);
return "true";
}