我需要在控制器中调用此API freegeoip.net/xml/userIpAddress
来获取其数据。像这样freegeoip.net/xml/4.2.2.2
这是我的控制器
public ActionResult Index(string language)
{
if (String.IsNullOrWhiteSpace(language) == false)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
}
else if (String.IsNullOrWhiteSpace(language))
{
string userIpAddress = this.Request.UserHostAddress;
//here how I can call freegeoip.net/xml/userIpAddress
}
}
这是XML响应的内容:
<Response>
<IP>4.2.2.2</IP>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
<RegionCode/>
<RegionName/>
<City/>
<ZipCode/>
<TimeZone/>
<Latitude>37.751</Latitude>
<Longitude>-97.822</Longitude>
<MetroCode>0</MetroCode>
</Response>
答案 0 :(得分:2)
使用func numberOfSections(in collectionView: UICollectionView) -> Int {
return items.count / 3 + 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return min(3, items.count - 3 * section)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let item = items[indexPath.section * 3 + item]
// do something with item
}
:
HttpClient