在swift 2之前,下面的代码曾经工作过。但是在升级到Swift 2后,我的代码不再有效。我已经使用Postman和RESTClient验证了我的Web服务是否有效。
let url = NSURL(string: "https://")
let mutableURL = NSMutableURLRequest(URL:url!)
mutableURL.HTTPMethod = "POST"
let str = "user_id=90031963"
mutableURL.HTTPBody = str.dataUsingEncoding(NSUTF8StringEncoding)
leaderboardWebView.loadRequest(mutableURL)
非常感谢任何评论和反馈。
干杯
答案 0 :(得分:1)
Swift2在安全在线连接方面非常严格。可能是连接被拒绝,因为您的服务器没有有效的ssh证书。出于测试目的,尝试将此词典添加到info.plist中:
poly1 = '4.0x^5 - 2.0x^3 + 2.0x + 3.0'
poly2 = '8.0x^4 + 4.0x^3 + -3.0x + 9.0'
# Makes component extraction from array easier.
coeff = 0
power = 1
def baseline(s):
# Remove spaces, normalise to all '+'.
check = s + ' '
result = s
while result != check:
check = result
result = result.replace(' ','');
result = result.replace('-','+-')
result = result.replace('++','+')
# Create array of terms.
result = result.split('+')
# Make each term a coefficient/power pair.
for i in range(len(result)):
result[i] = result[i].split('^')
if len(result[i]) == 1 and result[i][coeff].endswith('x'):
result[i].append('1')
if len(result[i]) == 1 and not result[i][coeff].endswith('x'):
result[i].append('0')
if result[i][coeff].endswith('x'):
result[i][coeff] = result[i][coeff][:-1]
result[i][coeff] = float(result[i][coeff])
result[i][power] = int(result[i][power])
return result
def polyprint(s,p):
print()
print(s, p, end=':\n ')
if len(p) > 0:
print(p[0][coeff],end='')
if p[0][power] == 1:
print('x',end='')
elif p[0][power] > 1:
print('x^%d' % (p[0][power]),end='')
for i in range(1,len(p)):
if p[i][coeff] < 0:
print(' -',-p[i][coeff],end='')
else:
print(' +',p[i][coeff],end='')
if p[i][power] == 1:
print('x',end='')
elif p[i][power] > 1:
print('x^%d' % (p[i][power]),end='')
print()
# Turn polynomials into sparse (based on powers) array.
poly1 = baseline(poly1)
poly2 = baseline(poly2)
polyprint('poly1',poly1)
polyprint('poly2',poly2)
# Add them as per sorted algorithm.
poly3 = []
idx1 = 0
idx2 = 0
while idx1 < len(poly1) and idx2 < len(poly2):
if poly1[idx1][power] == poly2[idx2][power]:
if poly1[idx1][coeff] != poly2[idx2][coeff]:
poly3.append([poly1[idx1][coeff] + poly2[idx2][coeff], poly1[idx1][power]])
idx1 += 1
idx2 += 1
continue
if poly1[idx1][power] > poly2[idx2][power]:
poly3.append([poly1[idx1][coeff], poly1[idx1][power]])
idx1 += 1
continue
poly3.append([poly2[idx2][coeff], poly2[idx2][power]])
idx2 += 1
while idx1 < len(poly1):
poly3.append([poly1[idx1][coeff], poly1[idx1][power]])
idx1 += 1
while idx2 < len(poly2):
poly3.append([poly2[idx2][coeff], poly2[idx2][power]])
idx2 += 1
polyprint('poly3',poly3)
如果有效,则表示您需要检查服务器安全设置。 您可以在此处详细了解它:https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/
请注意,除非您确实不需要安全连接,否则Apple不建议使用此词典。