• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Network Management Development
2
3
4## What are the data formats supported by extraData in an HTTP request? (API 9)
5
6**Solution**
7
8**extraData** indicates additional data in an HTTP request. It varies depending on the HTTP request method.
9
10- If the HTTP request uses a POST or PUT method, **extraData** serves as the content of the HTTP request.
11
12- If the HTTP request uses a GET, OPTIONS, DELETE, TRACE, or CONNECT method, **extraData** serves as a supplement to the HTTP request parameters and will be added to the URL when the request is sent.
13
14- If you pass in a string object, **extraData** contains the string encoded on your own.
15
16
17## What does error code 28 mean in the response to an HTTP request? (API 9)
18
19**Symptom**
20
21Error code 28 is reported after an HTTP request is initiated.
22
23**Solution**
24
25Error code 28 refers to **CURLE_OPERATION_TIMEDOUT**, which means a libcurl library operation timeout. For details, see any HTTP status code description available.
26
27**Reference**
28
29[Common HTTP Response Codes](../reference/apis/js-apis-http.md#responsecode) and [Curl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html)
30
31
32## What does error code 6 mean in the response to an HTTP request? (API 9)
33
34**Symptom**
35
36Error code 6 is reported after an HTTP request is initiated.
37
38**Solution**
39
40Error code 6 indicates a failure to resolve the host in the address. You can ping the URL carried in the request to check whether the host is accessible.
41
42**Reference**
43
44For more common error codes, see [Common HTTP Response Codes](../reference/apis/js-apis-http.md#responsecode) and [Curl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html).
45
46## How are parameters passed to queryParams of the POST request initiated by \@ohos/axios? (API 9)
47
48**Symptom**
49
50How are parameters passed to **queryParams** when the third-party component **\@ohos/axios** initiates a POST request?
51
52**Solution**
53
54- Method 1: Have the **axios.post** API receive only one parameter. The **Url.URLSearchParams** parameter needs to be converted into a string and appended to the end of the URL.
55
56  ```
57  let params:Url.URLSearchParams = new Url.URLSearchParams()
58  params.append('ctl', 'sug')
59  params.append('query', 'wangjunkai')
60  params.append('cfrom', '1099a')
61  axios.post('http://10.100.195.234:3000/save?' + params.toString()).then(res => {
62    this.message = "request result: " + JSON.stringify(res.data);
63  }).catch(err => {
64    this.message = "request error: " + err.message;
65  })
66  ```
67
68- Method 2: Have the **axios** API receive only one **config** object. The request parameters are written in **params** of the **config** object.
69
70  ```
71  axios({
72    url: 'http://10.100.195.234:3000/save',
73    method: 'post',
74    params: {
75    ctl: 'sug',
76    query: 'wangjunkai',
77    cfrom: '1099a'
78    }
79  }).then(res => {
80    this.message = "request result: " + JSON.stringify(res.data);
81  }).catch(err => {
82    this.message = "request error: " + err.message;
83  })
84  ```
85
86
87## What should I do if no data is returned after connection.getNetCapabilities\(mNetHandle\) is called? (API 9)
88
89**Symptom**
90
91No data is returned after **connection.getNetCapabilities()** is called. What should I do?
92
93**Possible Cause**
94
95This problem is due to incorrect pointing of the **this** object. You are expected to use **(err,data)=>{}** instead of **function(err,data)** to access the callback function to obtain the return result. The reason is that the function declared by **function** has its own **this** object and therefore cannot point to the **globalThis** object.
96
97**Solution**
98
99Change **function(err,data)** to **(err,data)** for the second parameter of **getNetCapabilities**.
100
101
102## How HTTP Requests Are Transmitted in JSON Format (API 9)
103
104**Solution**
105
106In the HTTP message header, **Content-Type** is used to indicate the media type information. It tells the server how to process the requested data and tells the client (usually a browser) how to parse the response data, for example, displaying an image, parsing HTML, or displaying only the text.
107
108To transmit data in HTTP requests in JSON format, set **Content-Type** to **application/json**.
109
110```
111this.options = {
112  method:  http.RequestMethod.GET,
113  extraData: this.extraData,
114  header: { 'Content-Type': 'application/json' },
115  readTimeout: 50000,
116  connectTimeout: 50000
117}
118```
119
120
121## How do I upload photos taken by a camera to the server? (API 9)
122
123**Symptom**
124
125After an application calls the camera to take a photo, how do I upload the photo to the server?
126
127**Solution**
128
129After the application is started and the permission is obtained, have the system access the remote server and transfer the locally saved photos to the remote server through the upload API.
130
131**Reference**
132
133[Upload and Download](../reference/apis/js-apis-request.md)
134
135
136## What should I do if calling connection.hasDefaultNet() fails even when the network is normal? (API 9)
137
138**Symptom**
139
140The network connection is normal, and web pages can be opened properly on the browser. However, calling the **hasDefaultNet** fails, and the callback function returns an error.
141
142**Solution**
143
144Declare the **ohos.permission.GET_NETWORK_INFO** permission when calling **connection.hasDefaultNet**.
145
146For details, see [Applying for Permissions](../security/accesstoken-guidelines.md).
147
148
149## What does netId mean in the netHandle object returned by connection.getDefaultNet? (API 9)
150
151**Symptom**
152
153What are the meanings of the values of **netId**, such as **0** and **100**?
154
155**Solution**
156
157If the value of **netId** is **0**, no network connection is available. In such a case, check and rectify network faults. If the value is greater than or equal to **100**, the network connection is normal.
158
159
160## How do I use HTTP requests to obtain data from the network? (API 9)
161
162**Solution**
163
164Use the **\@ohos.net.http** module to initiate an HTTP request.
165
1661. Import the **http** module and create an HTTP request.
167
1682. Set the request URL and parameters and initiate the HTTP request.
169
1703. Obtain the response and parse the data.
171
172**Reference**
173
174[HTTP Data Request](../connectivity/http-request.md)
175
176
177## How do I encapsulate network requests by using JavaScript? (API 9)
178
179**Solution**
180
181The JavaScript development mode is supported. You can directly use JavaScript to encapsulate network requests. For details, see [Network Connection](../reference/apis/js-apis-http.md).
182
183
184## How do I write network requests when developing a JavaScript-based application for smart watches? (API 9)
185
186**Solution**
187
188The JavaScript development mode is supported. You can directly use JavaScript to encapsulate network requests. For details, see [Network Connection](../reference/apis/js-apis-http.md).
189
190
191## Why does an application fail to start after the ohos.permission.NOTIFICATION_CONTROLLER permission is declared? (API 9)
192
193**Symptom**
194
195When an application is started, the following error message is reported w: error: install failed due to grant request permissions failed.
196
197**Solution**
198
199The **ohos.permission.NOTIFICATION_CONTROLLER** permission is a **system core** permission and is not available for third-party applications.
200
201
202## What should I do if an error is reported when wifi.getIpInfo\(\).ipAddress is used in the Wi-Fi module? (API 9)
203
204**Symptom**
205
206When **wifi.getIpInfo().ipAddress** is used in the Wi-Fi module, the following error message is reported: Error: assertion (wifiDevicePtr != nullptr) failed: Wifi device instance is null.
207
208**Solution**
209
210This problem is due to insufficient permissions. Check whether you have applied for the required permissions. For details, see [Permission Management](../security/accesstoken-overview.md).
211